fizz_buzz_dillonhafer 1.0.1 → 1.0.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/fizz_buzz_dillonhafer.gemspec +1 -1
- data/lib/fizz_buzz.rb +18 -20
- data/spec/fizz_buzz_spec.rb +9 -9
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2708da8f4902aa9e9b8db0f8f4ad899545c42189
         | 
| 4 | 
            +
              data.tar.gz: 174dc5daa0eddaa8f417b8abca016ed71933fda2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 54bb0f170cd3054920c9c0fa824707d049da810137287103875cd1f873fe4cfa6d877c3a42a8fecefe5922de3a0992f934059d805aa85bcbc3d608ad1533b57d
         | 
| 7 | 
            +
              data.tar.gz: 6ba36e83e87c7a0fb3e2d394b6028476ef480d5cd831b556f5c7c6a386c6f36fe94ed977b6aeeeae97956f22a22571af4de40864ba8750f302c80a6684d398a6
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        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 | 
            -
               | 
| 21 | 
            -
             | 
| 22 | 
            -
              def divisible?
         | 
| 23 | 
            -
                valid? && !definitions[find].nil?
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              def to_s
         | 
| 14 | 
            +
                convert if valid?
         | 
| 24 15 | 
             
              end
         | 
| 25 16 |  | 
| 26 | 
            -
               | 
| 27 | 
            -
                 | 
| 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  | 
| 31 | 
            -
                 | 
| 32 | 
            -
                 | 
| 33 | 
            -
                   | 
| 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
         | 
    
        data/spec/fizz_buzz_spec.rb
    CHANGED
    
    | @@ -13,44 +13,44 @@ describe FizzBuzz, "#valid?" do | |
| 13 13 | 
             
              end
         | 
| 14 14 | 
             
            end
         | 
| 15 15 |  | 
| 16 | 
            -
            describe FizzBuzz, "# | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 68 | 
            +
            rubygems_version: 2.4.2
         | 
| 69 69 | 
             
            signing_key: 
         | 
| 70 70 | 
             
            specification_version: 4
         | 
| 71 71 | 
             
            summary: FizzBuzz Kata!
         |