fizzbuzz_aj 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94991e3f3a79b170c35fdf76f363ababce161791
4
+ data.tar.gz: ce320d099c32c10332a2f041459ce646575dffac
5
+ SHA512:
6
+ metadata.gz: ff687701725057972ce70beb87ce86393d69a839702116c42e460e294ce0804e19b39ab902431d483b1684bf290852d72a73fa5665cc43167ceedec6151c80ca
7
+ data.tar.gz: bfdec347d16b2856cfe6ad0b8b9a81ae1411c810e6e12f3b308e721678c9cad5d086391f8d9bd35e486ccd179720a27a4228d9b54abfea508255d5848866ba3a
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fizzbuzz_aj.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrew Jarvis
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,47 @@
1
+ # Fizzbuzz_aj
2
+
3
+ A gem that contains the logic for a FizzBuzz program, you give it a maximum value and from 1 to max it wil return:
4
+
5
+ Fizz if the number is diviable by 3
6
+
7
+ Buzz if it is divisable by 5
8
+
9
+ FizzBuzz if it is divisable by 15
10
+
11
+ or the number if none of those are true
12
+
13
+ It also can reutrn the resualt in 3 different formats:
14
+
15
+ json
16
+
17
+ html
18
+
19
+ plain text
20
+
21
+ For example useage see: examples/example_usage.rb
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'fizzbuzz_aj'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install fizzbuzz_aj
36
+
37
+ ## Usage
38
+
39
+ FizzBuzz_aj performs the FizzBuzz calculations and format_aj formats the output
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/fizzbuzz_aj/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require 'fizzbuzz_aj'
2
+ fizzer = FizzBuzz.new(45)
3
+ fmats = Formats.new(fizzer.mapper)
4
+ puts fmats.as_html
5
+ puts fmats.as_json
6
+ puts fmats.as_plain
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fizzbuzz_aj/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fizzbuzz_aj"
8
+ spec.version = FizzbuzzAj::VERSION
9
+ spec.authors = ["Jarvis"]
10
+ spec.email = ["jarvisan@mail.gvsu.edu"]
11
+ spec.summary = %q{FizzBuzz gem}
12
+ spec.description = %q{A gem that contains the logic for a FizzBuzz program along with formatting options}
13
+ spec.homepage = "https://github.com/jarvisan/fizzbuzz_aj"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10"
23
+ spec.add_development_dependency "rspec", "~> 2"
24
+ spec.add_runtime_dependency "json", "~> 1"
25
+ end
@@ -0,0 +1,21 @@
1
+ class FizzBuzz
2
+ def initialize max
3
+ @max = max.to_i
4
+ end
5
+
6
+ def mapper
7
+ (1..@max).map{ |n| calc(n) }
8
+ end
9
+
10
+ def calc(n)
11
+ if(n % 15 == 0)
12
+ "FizzBuzz"
13
+ elsif (n % 3 == 0)
14
+ "Fizz"
15
+ elsif (n % 5 == 0)
16
+ "Buzz"
17
+ else
18
+ n
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ class Formats
3
+ def initialize ary
4
+ @ary = ary
5
+ end
6
+
7
+ def format_as fmt
8
+ if(fmt == "html")
9
+ as_html
10
+ elseif (fmt == "json")
11
+ as_json
12
+ else
13
+ as_plain
14
+ end
15
+ end
16
+
17
+ def as_plain
18
+ @ary.join(", ")
19
+ end
20
+
21
+ def as_json
22
+ @ary.to_json
23
+ end
24
+
25
+ def as_html
26
+ <<-EOF
27
+ #{@ary.map { |d| "<li>#{d}</li>"}.join("\n\t")}
28
+ EOF
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module FizzbuzzAj
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'fizzbuzz_aj/fizzbuzz.rb'
2
+ require 'fizzbuzz_aj/formats.rb'
@@ -0,0 +1,20 @@
1
+ require 'fizzbuzz_aj'
2
+
3
+ describe FizzBuzz do
4
+ fizz = FizzBuzz.new(42)
5
+ it "evaluates num%3" do
6
+ expect(fizz.calc(42)).to eq("Fizz")
7
+ end
8
+
9
+ it "evaluates num%5" do
10
+ expect(fizz.calc(40)).to eq("Buzz")
11
+ end
12
+
13
+ it "evaluates num%15" do
14
+ expect(fizz.calc(45)).to eq("FizzBuzz")
15
+ end
16
+
17
+ it "the rest" do
18
+ expect(fizz.calc(41)).to eq(41)
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fizzbuzz_aj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jarvis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ description: A gem that contains the logic for a FizzBuzz program along with formatting
70
+ options
71
+ email:
72
+ - jarvisan@mail.gvsu.edu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - examples/example_usage.rb
83
+ - fizzbuzz_aj.gemspec
84
+ - lib/fizzbuzz_aj.rb
85
+ - lib/fizzbuzz_aj/fizzbuzz.rb
86
+ - lib/fizzbuzz_aj/formats.rb
87
+ - lib/fizzbuzz_aj/version.rb
88
+ - spec/lib/fizzbuzz_aj_spec.rb
89
+ homepage: https://github.com/jarvisan/fizzbuzz_aj
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: FizzBuzz gem
113
+ test_files:
114
+ - spec/lib/fizzbuzz_aj_spec.rb