pebbles-fizzbuzz 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +57 -0
- data/Rakefile +9 -0
- data/lib/pebbles/fizzbuzz.rb +48 -0
- data/spec/pebbles-fizzbuzz_spec.rb +45 -0
- metadata +85 -0
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= pebbles-fizzbuzz
|
2
|
+
|
3
|
+
* https://github.com/kwappa/pebbles-fizzbuzz
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
It solves fizz-buzz
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* solve fizz-buzz
|
12
|
+
* solve sekaino-nabe-atsu
|
13
|
+
* return aho_nized string when value that multiples of 3 or includes `3` was given
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
require 'pebbles/fizzbuzz'
|
17
|
+
fizzbuzz 1 #=> '1'
|
18
|
+
fizzbuzz 3 #=> 'fizz'
|
19
|
+
fizzbuzz 5 #=> 'buzz'
|
20
|
+
fizzbuzz 15 #=> 'fizzbuzz'
|
21
|
+
|
22
|
+
nabeatsu 1 #=> '1'
|
23
|
+
nabeatsu 3 #=> '3 :P'
|
24
|
+
nabeatsu 13 #=> '13 :P'
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
|
28
|
+
* pebbles
|
29
|
+
|
30
|
+
== INSTALL
|
31
|
+
|
32
|
+
* gem install pebbles-fizzbuzz
|
33
|
+
|
34
|
+
== LICENSE:
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Copyright (c) 2011 SHIOYA, Hiromu
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
+
a copy of this software and associated documentation files (the
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
46
|
+
the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be
|
49
|
+
included in all copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'pebbles'
|
2
|
+
|
3
|
+
def fizzbuzz value
|
4
|
+
Fizzbuzz.solve value
|
5
|
+
end
|
6
|
+
|
7
|
+
def nabeatsu value
|
8
|
+
Fizzbuzz.nabeatsu value
|
9
|
+
end
|
10
|
+
|
11
|
+
class Pebbles::Fizzbuzz
|
12
|
+
VERSION = '0.1.0'
|
13
|
+
|
14
|
+
def self.solve value
|
15
|
+
value = self.validate value
|
16
|
+
|
17
|
+
result = ''
|
18
|
+
if value % 3 == 0
|
19
|
+
result += 'fizz'
|
20
|
+
end
|
21
|
+
if value % 5 == 0
|
22
|
+
result += 'buzz'
|
23
|
+
end
|
24
|
+
return result unless result.empty?
|
25
|
+
|
26
|
+
return value.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.nabeatsu value
|
30
|
+
value = self.validate value
|
31
|
+
result = value.to_s
|
32
|
+
if value % 3 == 0 || result.include?('3')
|
33
|
+
result = self.aho_nize result
|
34
|
+
end
|
35
|
+
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.validate value
|
40
|
+
raise ArgumentError unless value.kind_of? Integer
|
41
|
+
raise ArgumentError unless value > 0
|
42
|
+
value
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.aho_nize str
|
46
|
+
return "#{str} :P"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), %w(.. lib pebbles fizzbuzz))
|
2
|
+
|
3
|
+
describe Fizzbuzz do
|
4
|
+
context '.solve with valid value' do
|
5
|
+
it 'retunrs string converted value when integer value was given' do
|
6
|
+
Fizzbuzz.solve(1).should eql '1'
|
7
|
+
end
|
8
|
+
it 'returns `fizz` when mutliples of 3 was given' do
|
9
|
+
Fizzbuzz.solve(3).should eql 'fizz'
|
10
|
+
Fizzbuzz.solve(9).should eql 'fizz'
|
11
|
+
end
|
12
|
+
it 'returns `buzz` when multiples 5 was given' do
|
13
|
+
Fizzbuzz.solve(5).should eql 'buzz'
|
14
|
+
Fizzbuzz.solve(25).should eql 'buzz'
|
15
|
+
end
|
16
|
+
it 'returns `fizzbuzz` when multiples both 3 and 5 was given' do
|
17
|
+
Fizzbuzz.solve(15).should eql 'fizzbuzz'
|
18
|
+
Fizzbuzz.solve(75).should eql 'fizzbuzz'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.solve with invalid value' do
|
23
|
+
it 'raises ArgumentError when string value was given' do
|
24
|
+
expect { Fizzbuzz.solve('hoge') }.to raise_error ArgumentError
|
25
|
+
end
|
26
|
+
it 'raises ArgumentError when value equal or less zan zero was given' do
|
27
|
+
expect { Fizzbuzz.solve(-1) }.to raise_error ArgumentError
|
28
|
+
expect { Fizzbuzz.solve( 0) }.to raise_error ArgumentError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '.nabeatsu with valid value' do
|
33
|
+
it 'retunrs string converted value when integer value was given' do
|
34
|
+
Fizzbuzz.nabeatsu(1).should eql '1'
|
35
|
+
end
|
36
|
+
it 'returns string converted value with facemark when multiples of 3 was given' do
|
37
|
+
Fizzbuzz.nabeatsu( 3).should eql Fizzbuzz.aho_nize('3')
|
38
|
+
Fizzbuzz.nabeatsu(72).should eql Fizzbuzz.aho_nize('72')
|
39
|
+
end
|
40
|
+
it 'returns string converted value with facemark when include character `3` value was given' do
|
41
|
+
Fizzbuzz.nabeatsu(13).should eql Fizzbuzz.aho_nize('13')
|
42
|
+
Fizzbuzz.nabeatsu(35).should eql Fizzbuzz.aho_nize('35')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pebbles-fizzbuzz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SHIOYA, Hiromu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: pebbles
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hoe
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.9.4
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description: It solves fizz-buzz
|
38
|
+
email:
|
39
|
+
- kwappa.856@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
files:
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
- Rakefile
|
53
|
+
- lib/pebbles/fizzbuzz.rb
|
54
|
+
- spec/pebbles-fizzbuzz_spec.rb
|
55
|
+
- .gemtest
|
56
|
+
homepage: https://github.com/kwappa/pebbles-fizzbuzz
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --main
|
62
|
+
- README.txt
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: pebbles-fizzbuzz
|
80
|
+
rubygems_version: 1.8.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: It solves fizz-buzz
|
84
|
+
test_files: []
|
85
|
+
|