diff --git a/.ruby-version b/.ruby-version index 7208c21..197c4d5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4 \ No newline at end of file +2.4.0 diff --git a/models/sarahb_fizzbuzz.rb b/models/sarahb_fizzbuzz.rb new file mode 100644 index 0000000..9165a3f --- /dev/null +++ b/models/sarahb_fizzbuzz.rb @@ -0,0 +1,27 @@ + +class Fizzbuzz + + def initialize number + @fizzbuzz = number + end + + def string + x = @fizzbuzz + case + when x % 3 == 0 && x % 5 == 0 + "fizzbuzz" + when x % 3 == 0 + "fizz" + when x % 5 == 0 + "buzz" + else + x + end + end +end + + +(1..100).each do |n| + fb = Fizzbuzz.new(n) + puts (fb.string) +end diff --git a/specs/models/sarahb_fizzbuzz_spec.rb b/specs/models/sarahb_fizzbuzz_spec.rb new file mode 100644 index 0000000..0b416f5 --- /dev/null +++ b/specs/models/sarahb_fizzbuzz_spec.rb @@ -0,0 +1,25 @@ +require 'rspec' +require_relative "../../models/sarahb_fizzbuzz" + +describe 'fizzbuzz' do + it " returns 1" do + fb = Fizzbuzz.new(1) + expect(fb.string).to eq(1) + end + it "returns fizz for a multiple of 3" do + fb = Fizzbuzz.new(3) + expect(fb.string).to eq('fizz') + end + it 'returns buzz for a multiple 5' do + fb = Fizzbuzz.new(5) + expect(fb.string).to eq('buzz') + + end + it 'returns fizzbuzz for multiples of 3 and 5' do + fb = Fizzbuzz.new(15) + expect(fb.string).to eq('fizzbuzz') + end + +end + +puts Fizzbuzz.new(15).string