fizz_buzz_dillonhafer 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6fdcf120be1e851e0ccef304c10fedce723071f
4
- data.tar.gz: c3a9466cf694c527a4a0d7ef12251e491871c89b
3
+ metadata.gz: 2708da8f4902aa9e9b8db0f8f4ad899545c42189
4
+ data.tar.gz: 174dc5daa0eddaa8f417b8abca016ed71933fda2
5
5
  SHA512:
6
- metadata.gz: 6f5dc55d940b29f01a49811571d4ef5555d4e7ca89a08708cc0438365e5a0f8b82b3fe5b3d2d75485d9c9b36f265a6d2266145e2e2e412a2f05fcaf199ffba7e
7
- data.tar.gz: 337a43b00af7654458bf2446c3c7da378a850c57f08ef2fd8046965905e78b99f160a8c533c2104f76a2bd7001d283eda2d65398e41526660ab22f83e60aa749
6
+ metadata.gz: 54bb0f170cd3054920c9c0fa824707d049da810137287103875cd1f873fe4cfa6d877c3a42a8fecefe5922de3a0992f934059d805aa85bcbc3d608ad1533b57d
7
+ data.tar.gz: 6ba36e83e87c7a0fb3e2d394b6028476ef480d5cd831b556f5c7c6a386c6f36fe94ed977b6aeeeae97956f22a22571af4de40864ba8750f302c80a6684d398a6
data/Gemfile.lock CHANGED
@@ -25,4 +25,4 @@ PLATFORMS
25
25
 
26
26
  DEPENDENCIES
27
27
  fizz_buzz_dillonhafer!
28
- rspec (~> 3.1.0)
28
+ rspec (~> 3.1.0, >= 3.1.0)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fizz_buzz_dillonhafer'
3
- s.version = '1.0.1'
3
+ s.version = '1.0.2'
4
4
  s.date = '2014-10-02'
5
5
  s.summary = "FizzBuzz Kata!"
6
6
  s.description = "FizzBuzz"
data/lib/fizz_buzz.rb CHANGED
@@ -1,37 +1,35 @@
1
1
  class FizzBuzz
2
+ DEFINITIONS = {'3' => 'fizz', '5' => 'buzz'}
2
3
  attr_accessor :number
3
4
 
4
5
  def initialize(number)
5
6
  @number = number
6
7
  end
7
8
 
8
- def word
9
- if divisible?
10
- definitions[find]
11
- else
12
- number
13
- end
14
- end
15
-
16
9
  def valid?
17
10
  number > 0
18
11
  end
19
-
20
- private
21
-
22
- def divisible?
23
- valid? && !definitions[find].nil?
12
+
13
+ def to_s
14
+ convert if valid?
24
15
  end
25
16
 
26
- def definitions
27
- {'3' => 'fizz', '5' => 'buzz', '15' => 'fizzbuzz'}
17
+ private
18
+
19
+ def calculate
20
+ match = ""
21
+ %w{3 5}.each do |n|
22
+ match << DEFINITIONS[n] if number % n.to_i == 0
23
+ end
24
+ match
28
25
  end
29
26
 
30
- def find
31
- match = number
32
- %w{3 5 15}.each do |n|
33
- match = n if number % n.to_i == 0
27
+ def convert
28
+ result = calculate
29
+ if result.empty?
30
+ number
31
+ else
32
+ result
34
33
  end
35
- match
36
34
  end
37
35
  end
@@ -13,44 +13,44 @@ describe FizzBuzz, "#valid?" do
13
13
  end
14
14
  end
15
15
 
16
- describe FizzBuzz, "#word" do
16
+ describe FizzBuzz, "#to_s" do
17
17
  it "returns 1 if 1 not divisible by 3, 5, or 15" do
18
18
  fizz_buzz = FizzBuzz.new(1)
19
- expect(fizz_buzz.word).to eq(1)
19
+ expect(fizz_buzz.to_s).to eq(1)
20
20
  end
21
21
 
22
22
  it "returns 2 if 2 not divisible by 3, 5, or 15" do
23
23
  fizz_buzz = FizzBuzz.new(2)
24
- expect(fizz_buzz.word).to eq(2)
24
+ expect(fizz_buzz.to_s).to eq(2)
25
25
  end
26
26
 
27
27
  it "returns 'fizz' if the number is divisible by 3" do
28
28
  fizz_buzz = FizzBuzz.new(3)
29
- expect(fizz_buzz.word).to eq('fizz')
29
+ expect(fizz_buzz.to_s).to eq('fizz')
30
30
  end
31
31
 
32
32
  it "returns 4 if 4 is not divisible by 3, 5, or 15" do
33
33
  fizz_buzz = FizzBuzz.new(4)
34
- expect(fizz_buzz.word).to eq(4)
34
+ expect(fizz_buzz.to_s).to eq(4)
35
35
  end
36
36
 
37
37
  it "returns 'buzz' if the number is divisible by 5" do
38
38
  fizz_buzz = FizzBuzz.new(5)
39
- expect(fizz_buzz.word).to eq('buzz')
39
+ expect(fizz_buzz.to_s).to eq('buzz')
40
40
  end
41
41
 
42
42
  it "returns 'fixx' if the number is divisible by 3" do
43
43
  fizz_buzz = FizzBuzz.new(6)
44
- expect(fizz_buzz.word).to eq('fizz')
44
+ expect(fizz_buzz.to_s).to eq('fizz')
45
45
  end
46
46
 
47
47
  it "returns 'buzz' if the number is divisible by 5" do
48
48
  fizz_buzz = FizzBuzz.new(10)
49
- expect(fizz_buzz.word).to eq('buzz')
49
+ expect(fizz_buzz.to_s).to eq('buzz')
50
50
  end
51
51
 
52
52
  it "returns 'fizzbuzz' if the number is divisible by 15" do
53
53
  fizz_buzz = FizzBuzz.new(15)
54
- expect(fizz_buzz.word).to eq('fizzbuzz')
54
+ expect(fizz_buzz.to_s).to eq('fizzbuzz')
55
55
  end
56
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fizz_buzz_dillonhafer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dillon Hafer
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 2.2.2
68
+ rubygems_version: 2.4.2
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: FizzBuzz Kata!