fizz_buzz_dillonhafer 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f0ff838051b768d04234845a618830b1a364599
4
- data.tar.gz: c923536a430874f4c36ed7add6ae7b9dc2adb511
3
+ metadata.gz: b6fdcf120be1e851e0ccef304c10fedce723071f
4
+ data.tar.gz: c3a9466cf694c527a4a0d7ef12251e491871c89b
5
5
  SHA512:
6
- metadata.gz: 0fc3dfd8ed0718c99e3620278ec9f6cc094ff99d9d0b28777023cb724124931fa5f3a49e94094bbce19c3bf16aeaad0eaa693b3ba0764ea404e49e33cbb284b9
7
- data.tar.gz: aee345ecb06837674c060510640e55659530548de4ba72376a20876d3d89599c3d38f016b24da5fd0b844b2a8c99ec889bb36d0d0c2684f78db8ae04bd68807b
6
+ metadata.gz: 6f5dc55d940b29f01a49811571d4ef5555d4e7ca89a08708cc0438365e5a0f8b82b3fe5b3d2d75485d9c9b36f265a6d2266145e2e2e412a2f05fcaf199ffba7e
7
+ data.tar.gz: 337a43b00af7654458bf2446c3c7da378a850c57f08ef2fd8046965905e78b99f160a8c533c2104f76a2bd7001d283eda2d65398e41526660ab22f83e60aa749
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ nbproject
5
+ *.swp
6
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fizz_buzz_dillonhafer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fizz_buzz_dillonhafer (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rspec (3.1.0)
11
+ rspec-core (~> 3.1.0)
12
+ rspec-expectations (~> 3.1.0)
13
+ rspec-mocks (~> 3.1.0)
14
+ rspec-core (3.1.5)
15
+ rspec-support (~> 3.1.0)
16
+ rspec-expectations (3.1.2)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.1.0)
19
+ rspec-mocks (3.1.2)
20
+ rspec-support (~> 3.1.0)
21
+ rspec-support (3.1.1)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ fizz_buzz_dillonhafer!
28
+ rspec (~> 3.1.0)
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Fizz Buzz
2
+
3
+ This is a test gem to perform the Fizz Buzz kata.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'fizz_buzz_dillonhafer'
3
+ s.version = '1.0.1'
4
+ s.date = '2014-10-02'
5
+ s.summary = "FizzBuzz Kata!"
6
+ s.description = "FizzBuzz"
7
+ s.authors = ["Dillon Hafer"]
8
+ s.email = 'dh@dillonhafer.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
+ s.homepage =
12
+ 'https://github.com/thealtair/fizz-buzz'
13
+ s.license = 'MIT'
14
+ s.require_paths = ["lib"]
15
+ s.add_development_dependency 'rspec', '~> 3.1.0', '>= 3.1.0'
16
+ end
data/lib/fizz_buzz.rb CHANGED
@@ -1,35 +1,37 @@
1
1
  class FizzBuzz
2
- attr_accessor :number
2
+ attr_accessor :number
3
3
 
4
4
  def initialize(number)
5
- @number = number
5
+ @number = number
6
+ end
7
+
8
+ def word
9
+ if divisible?
10
+ definitions[find]
11
+ else
12
+ number
13
+ end
6
14
  end
7
15
 
8
16
  def valid?
9
17
  number > 0
10
18
  end
11
19
 
12
- def result
13
- return unless valid?
14
- case parse
15
- when 3
16
- 'fizz'
17
- when 5
18
- 'buzz'
19
- when 15
20
- 'fizzbuzz'
21
- else
22
- number
23
- end
20
+ private
21
+
22
+ def divisible?
23
+ valid? && !definitions[find].nil?
24
24
  end
25
25
 
26
- private
26
+ def definitions
27
+ {'3' => 'fizz', '5' => 'buzz', '15' => 'fizzbuzz'}
28
+ end
27
29
 
28
- def parse
29
- match = 0
30
- [3,5,15].each do |n|
31
- match = n if number % n == 0
30
+ def find
31
+ match = number
32
+ %w{3 5 15}.each do |n|
33
+ match = n if number % n.to_i == 0
32
34
  end
33
35
  match
34
36
  end
35
- end
37
+ end
@@ -0,0 +1,56 @@
1
+ require 'rspec'
2
+ require 'fizz_buzz'
3
+
4
+ describe FizzBuzz, "#valid?" do
5
+ it 'fails for numbers less than 1' do
6
+ fizz_buzz = FizzBuzz.new(0)
7
+ expect(fizz_buzz.valid?).to eq(false)
8
+ end
9
+
10
+ it 'succeeds for numbers greater than 0' do
11
+ fizz_buzz = FizzBuzz.new(1)
12
+ expect(fizz_buzz.valid?).to eq(true)
13
+ end
14
+ end
15
+
16
+ describe FizzBuzz, "#word" do
17
+ it "returns 1 if 1 not divisible by 3, 5, or 15" do
18
+ fizz_buzz = FizzBuzz.new(1)
19
+ expect(fizz_buzz.word).to eq(1)
20
+ end
21
+
22
+ it "returns 2 if 2 not divisible by 3, 5, or 15" do
23
+ fizz_buzz = FizzBuzz.new(2)
24
+ expect(fizz_buzz.word).to eq(2)
25
+ end
26
+
27
+ it "returns 'fizz' if the number is divisible by 3" do
28
+ fizz_buzz = FizzBuzz.new(3)
29
+ expect(fizz_buzz.word).to eq('fizz')
30
+ end
31
+
32
+ it "returns 4 if 4 is not divisible by 3, 5, or 15" do
33
+ fizz_buzz = FizzBuzz.new(4)
34
+ expect(fizz_buzz.word).to eq(4)
35
+ end
36
+
37
+ it "returns 'buzz' if the number is divisible by 5" do
38
+ fizz_buzz = FizzBuzz.new(5)
39
+ expect(fizz_buzz.word).to eq('buzz')
40
+ end
41
+
42
+ it "returns 'fixx' if the number is divisible by 3" do
43
+ fizz_buzz = FizzBuzz.new(6)
44
+ expect(fizz_buzz.word).to eq('fizz')
45
+ end
46
+
47
+ it "returns 'buzz' if the number is divisible by 5" do
48
+ fizz_buzz = FizzBuzz.new(10)
49
+ expect(fizz_buzz.word).to eq('buzz')
50
+ end
51
+
52
+ it "returns 'fizzbuzz' if the number is divisible by 15" do
53
+ fizz_buzz = FizzBuzz.new(15)
54
+ expect(fizz_buzz.word).to eq('fizzbuzz')
55
+ end
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.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dillon Hafer
@@ -9,15 +9,43 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-10-02 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.0
13
33
  description: FizzBuzz
14
34
  email: dh@dillonhafer.com
15
35
  executables: []
16
36
  extensions: []
17
37
  extra_rdoc_files: []
18
38
  files:
39
+ - ".gitignore"
40
+ - ".rspec"
41
+ - Gemfile
42
+ - Gemfile.lock
43
+ - README.md
44
+ - Rakefile
45
+ - fizz_buzz_dillonhafer.gemspec
19
46
  - lib/fizz_buzz.rb
20
- homepage: http://rubygems.org/gems/fizz_buzz_dillonhafer
47
+ - spec/fizz_buzz_spec.rb
48
+ homepage: https://github.com/thealtair/fizz-buzz
21
49
  licenses:
22
50
  - MIT
23
51
  metadata: {}
@@ -41,4 +69,5 @@ rubygems_version: 2.2.2
41
69
  signing_key:
42
70
  specification_version: 4
43
71
  summary: FizzBuzz Kata!
44
- test_files: []
72
+ test_files:
73
+ - spec/fizz_buzz_spec.rb