bradley_fizzbuzz 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## v.0.0.1
2
+
3
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bradley_fizzbuzz.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 DVG
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # BradleyFizzbuzz
2
+
3
+ BradleyFizzbuzz, a gemified, test-driven fizzbuzz gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bradley_fizzbuzz'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bradley_fizzbuzz
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ [1, 2, 3, 4, 5].fizzbuzz # => [1, 2, "fizz", 4, "buzz"]
23
+ (1..5).fizzbuzz # => [1, 2, "fizz", 4, "buzz"]
24
+ [15].fizzbuzz # => ["fizzbuzz"]
25
+ 1.fizz? # => false
26
+ 3.fizz? # => true
27
+ 5.fizz? # => false
28
+ 3.buzz? # => false
29
+ 5.buzz? # => true
30
+ 1.fizzbuzz? # => false
31
+ 15.fizzbuzz? # => true
32
+ ```
33
+
34
+ Additionally `print_fizzbuzz` will send all the values for a given array or range to `$stdout`
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bradley_fizzbuzz/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bradley_fizzbuzz"
8
+ gem.version = BradleyFizzbuzz::VERSION
9
+ gem.authors = ["DVG"]
10
+ gem.email = ["devryguy@gmail.com"]
11
+ gem.description = %q{To fizzbuzz arrays and ranges}
12
+ gem.summary = %q{Replace and array or range of numbers with a fizzbuzzed array, or print it out}
13
+ gem.homepage = "http://www.github.com/DVG/bradley_fizzbuzz"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ end
@@ -0,0 +1,53 @@
1
+ require "bradley_fizzbuzz/version"
2
+
3
+ module BradleyFizzbuzz
4
+ def fizzbuzz
5
+ array = Array.new
6
+
7
+ self.each do |n|
8
+ if n.fizzbuzz?
9
+ array << "fizzbuzz"
10
+ elsif n.buzz?
11
+ array << "buzz"
12
+ elsif n.fizz?
13
+ array << "fizz"
14
+ else
15
+ array << n
16
+ end
17
+ end
18
+
19
+ array
20
+ end
21
+
22
+ def print_fizzbuzz
23
+ self.fizzbuzz.each do |value|
24
+ puts value
25
+ end
26
+ end
27
+ end
28
+
29
+ module FizzBuzzNumerics
30
+ def fizz?
31
+ self % 3 == 0
32
+ end
33
+
34
+ def buzz?
35
+ self % 5 == 0
36
+ end
37
+
38
+ def fizzbuzz?
39
+ self % 5 == 0 && self % 3 == 0
40
+ end
41
+ end
42
+
43
+ class Numeric
44
+ include FizzBuzzNumerics
45
+ end
46
+
47
+ class Array
48
+ include BradleyFizzbuzz
49
+ end
50
+
51
+ class Range
52
+ include BradleyFizzbuzz
53
+ end
@@ -0,0 +1,3 @@
1
+ module BradleyFizzbuzz
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "FizzBuzz" do
4
+ context "fizz?" do
5
+ it "returns true for numbers divisible by 3" do
6
+ 3.fizz?.should be_true
7
+ end
8
+ it "returns false for numbers not divisible by 3" do
9
+ 5.fizz?.should be_false
10
+ end
11
+ end
12
+
13
+ context "buzz?" do
14
+ it "returns true for numbers divisible by 5" do
15
+ 5.buzz?.should be_true
16
+ end
17
+ it "returns false for numbers not divisible by 5" do
18
+ 3.buzz?.should be_false
19
+ end
20
+ end
21
+
22
+ context "fizzbuzz?" do
23
+ it "returns true for numbers divisible by 15" do
24
+ 15.fizzbuzz?.should be_true
25
+ end
26
+ it "returns false for numbers not divisible by 15" do
27
+ 3.fizzbuzz?.should be_false
28
+ end
29
+ end
30
+
31
+ context "Array" do
32
+ it "should return an array with values fizzbuzzed" do
33
+ [3, 5, 15, 16].fizzbuzz.should == ["fizz", "buzz", "fizzbuzz", 16]
34
+ end
35
+ end
36
+
37
+ context "Range" do
38
+ it "should return an array with the values fizzbuzzed" do
39
+ (1..15).fizzbuzz.should == [1, 2, "fizz", 4, "buzz", "fizz", 7, 8, "fizz", "buzz", 11, "fizz", 13, 14, "fizzbuzz"]
40
+ end
41
+ end
42
+
43
+ context "Output" do
44
+ context "Array" do
45
+ it "should pring out the fizzbuzzy values" do
46
+ $stdout.should_receive(:puts).and_return("fizz", "buzz", "fizzbuzz", 16)
47
+ [3, 5, 15, 16].print_fizzbuzz
48
+ end
49
+ end
50
+ context "Range" do
51
+ it "should pring out the fizzbuzzy values" do
52
+ $stdout.should_receive(:puts).and_return("1", "2", "fizz", "4", "buzz", "fizz", "7", "8",
53
+ "fizz", "buzz", "11", "fizz", "13", "14", "fizzbuzz")
54
+ (1..15).print_fizzbuzz
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ require 'bradley_fizzbuzz'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run :focus
5
+ config.mock_with :rspec
6
+ config.order = 'random'
7
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bradley_fizzbuzz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - DVG
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-06 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70262063902260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70262063902260
25
+ description: To fizzbuzz arrays and ranges
26
+ email:
27
+ - devryguy@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .rspec
34
+ - CHANGELOG
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - bradley_fizzbuzz.gemspec
40
+ - lib/bradley_fizzbuzz.rb
41
+ - lib/bradley_fizzbuzz/version.rb
42
+ - spec/bradley_fizzbuzz/bradley_fizzbuzz_spec.rb
43
+ - spec/spec_helper.rb
44
+ homepage: http://www.github.com/DVG/bradley_fizzbuzz
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.10
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Replace and array or range of numbers with a fizzbuzzed array, or print it
68
+ out
69
+ test_files:
70
+ - spec/bradley_fizzbuzz/bradley_fizzbuzz_spec.rb
71
+ - spec/spec_helper.rb