nutella 0.5.1.1 → 0.6

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.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --order random
3
+ --format Fuubar
@@ -0,0 +1,19 @@
1
+ class Integer
2
+ # Returns a string with the ordinal form of a given integer.
3
+ #
4
+ # 1.ordinalize # => "1st"
5
+ # 2.ordinalize # => "2nd"
6
+ # 9.ordinalize # => "9th"
7
+ # 43.ordinalize # => "43rd"
8
+ def ordinalize
9
+ suffixes = { 1 => "st", 2 => "nd", 3 => "rd" }
10
+
11
+ self.to_s + if (11..13).include?(self.abs % 100)
12
+ "th"
13
+ elsif suffixes.keys.include? (last_digit = self.abs % 10)
14
+ suffixes[last_digit]
15
+ else
16
+ "th"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,63 @@
1
+ class Integer
2
+ # Checks whether the integer goes evenly into all of the arguments
3
+ #
4
+ # @example Check if 3 goes into some numbers
5
+ # 3.goes_into? 10 # => false
6
+ # 3.goes_into? 6 # => true
7
+ #
8
+ # @example Check if 5 goes into every number in some sets of numbers
9
+ # 5.goes_into? 10, 12 # => false
10
+ # 5.goes_into? 10, 20 # => true
11
+ #
12
+ # @param [*Integer] nums the integer(s) to check against
13
+ # @return [Boolean] whether or not the integer goes evenly into all of the
14
+ # arguments
15
+ def goes_into?(*nums)
16
+ nums.all? { |n| (!zero? && n % self == 0) || n.zero? }
17
+ end
18
+
19
+ # Checks whether the integer goes evenly into any of the arguments
20
+ #
21
+ # @example Check if 5 goes into every number in some sets of numbers
22
+ # 5.goes_into_any? 10, 20 # => true
23
+ # 5.goes_into_any? 10, 12 # => true
24
+ # 5.goes_into_any? 12, 21 # => false
25
+ #
26
+ # @param [*Integer] nums the integer(s) to check against
27
+ # @return [Boolean] whether or not the integer goes evenly into any of the
28
+ # arguments
29
+ def goes_into_any?(*nums)
30
+ nums.any? { |n| goes_into? n }
31
+ end
32
+
33
+ # Checks whether the integer is evenly divisible by all of the arguments.
34
+ #
35
+ # @example Check if some numbers are evenly divisible by 5
36
+ # 4.multiple_of? 5 # => false
37
+ # 30.multiple_of? 5 # => true
38
+ #
39
+ # @example Check if some numbers are evenly divisible by both 4 and 7
40
+ # 10.multiple_of? 4, 7 # => false
41
+ # 56.multiple_of? 4, 7 # => true
42
+ #
43
+ # @param [*Integer] nums the integer(s) to check against
44
+ # @return [Boolean] whether or not the integer is evenly divisible by all
45
+ # arguments
46
+ def multiple_of?(*nums)
47
+ nums.all? { |n| (!n.zero? && self % n == 0) || zero? }
48
+ end
49
+ alias_method :divisible_by?, :multiple_of?
50
+
51
+ # Checks whether the integer is evenly divisible by any of the arguments.
52
+ #
53
+ # @example {Project Euler #1}[http://projecteuler.net/problem=1] solution using Nutella
54
+ # (1...1000).sum { |n| n.multiple_of_any?(3, 5) }
55
+ #
56
+ # @param [*Integer] nums the integer(s) to check against
57
+ # @return [Boolean] whether or not the integer is evenly divisible by any
58
+ # arguments
59
+ def multiple_of_any?(*nums)
60
+ nums.any? { |n| multiple_of? n }
61
+ end
62
+ alias_method :divisible_by_any?, :multiple_of_any?
63
+ end
@@ -1,63 +1 @@
1
- class Integer
2
- # Checks whether the integer goes evenly into all of the arguments
3
- #
4
- # @example Check if 3 goes into some numbers
5
- # 3.goes_into? 10 # => false
6
- # 3.goes_into? 6 # => true
7
- #
8
- # @example Check if 5 goes into every number in some sets of numbers
9
- # 5.goes_into? 10, 12 # => false
10
- # 5.goes_into? 10, 20 # => true
11
- #
12
- # @param [*Integer] nums the integer(s) to check against
13
- # @return [Boolean] whether or not the integer goes evenly into all of the
14
- # arguments
15
- def goes_into?(*nums)
16
- nums.all? { |n| (!zero? && n % self == 0) || n.zero? }
17
- end
18
-
19
- # Checks whether the integer goes evenly into any of the arguments
20
- #
21
- # @example Check if 5 goes into every number in some sets of numbers
22
- # 5.goes_into_any? 10, 20 # => true
23
- # 5.goes_into_any? 10, 12 # => true
24
- # 5.goes_into_any? 12, 21 # => false
25
- #
26
- # @param [*Integer] nums the integer(s) to check against
27
- # @return [Boolean] whether or not the integer goes evenly into any of the
28
- # arguments
29
- def goes_into_any?(*nums)
30
- nums.any? { |n| goes_into? n }
31
- end
32
-
33
- # Checks whether the integer is evenly divisible by all of the arguments.
34
- #
35
- # @example Check if some numbers are evenly divisible by 5
36
- # 4.multiple_of? 5 # => false
37
- # 30.multiple_of? 5 # => true
38
- #
39
- # @example Check if some numbers are evenly divisible by both 4 and 7
40
- # 10.multiple_of? 4, 7 # => false
41
- # 56.multiple_of? 4, 7 # => true
42
- #
43
- # @param [*Integer] nums the integer(s) to check against
44
- # @return [Boolean] whether or not the integer is evenly divisible by all
45
- # arguments
46
- def multiple_of?(*nums)
47
- nums.all? { |n| (!n.zero? && self % n == 0) || zero? }
48
- end
49
- alias_method :divisible_by?, :multiple_of?
50
-
51
- # Checks whether the integer is evenly divisible by any of the arguments.
52
- #
53
- # @example {Project Euler #1}[http://projecteuler.net/problem=1] solution using Nutella
54
- # (1...1000).sum { |n| n.multiple_of_any?(3, 5) }
55
- #
56
- # @param [*Integer] nums the integer(s) to check against
57
- # @return [Boolean] whether or not the integer is evenly divisible by any
58
- # arguments
59
- def multiple_of_any?(*nums)
60
- nums.any? { |n| multiple_of? n }
61
- end
62
- alias_method :divisible_by_any?, :multiple_of_any?
63
- end
1
+ Dir[File.expand_path("../integer/**/*.rb", __FILE__)].each { |f| require f }
@@ -1,4 +1,4 @@
1
1
  module Nutella
2
2
  # The current version of Nutella.
3
- VERSION = "0.5.1.1"
3
+ VERSION = "0.6"
4
4
  end
data/nutella.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  ]
21
21
 
22
22
  gem.required_ruby_version = "~> 1.9"
23
+ gem.add_development_dependency "fuubar", "~> 1.1"
23
24
  gem.add_development_dependency "rake", "~> 0.9"
24
25
  gem.add_development_dependency "redcarpet", "~> 2.1"
25
26
  gem.add_development_dependency "rdoc", "~> 3.0"
@@ -48,9 +48,7 @@ describe Enumerable do
48
48
  end
49
49
 
50
50
  describe "#group!" do
51
- arr = []
52
-
53
- before { arr = (1..10).to_a }
51
+ let(:arr) { (1..10).to_a }
54
52
 
55
53
  it "should modify in place" do
56
54
  arr.group! 2
@@ -2,16 +2,14 @@ require "spec_helper"
2
2
  require "nutella/core_ext/hash"
3
3
 
4
4
  describe Hash do
5
+ let(:hash) { { a: 1, b: 2, c: 3, d: 4 } }
6
+
5
7
  describe "aliases" do
6
8
  test_alias Hash, :slice, :grab
7
9
  test_alias Hash, :slice!, :grab!
8
10
  end
9
11
 
10
12
  describe "#grab" do
11
- hash = {}
12
-
13
- before { hash = { a: 1, b: 2, c: 3, d: 4 } }
14
-
15
13
  it "should select the given items from a hash" do
16
14
  hash.slice(:a, :c).should == { a: 1, c: 3 }
17
15
  end
@@ -28,10 +26,6 @@ describe Hash do
28
26
  end
29
27
 
30
28
  describe "#grab!" do
31
- hash = {}
32
-
33
- before { hash = { a: 1, b: 2, c: 3, d: 4 } }
34
-
35
29
  it "should modify in place" do
36
30
  hash.slice! :a, :c
37
31
  hash.should == { a: 1, c: 3 }
@@ -7,6 +7,14 @@ describe Integer do
7
7
  test_alias Integer, :divisible_by_any?, :multiple_of_any?
8
8
  end
9
9
 
10
+ describe "#ordinalize" do
11
+ it "should return the cardinal form of a given integer" do
12
+ NUMBER_FORMATS.each do |cardinal, ordinal|
13
+ cardinal.ordinalize.should == ordinal
14
+ end
15
+ end
16
+ end
17
+
10
18
  describe "#goes_into?" do
11
19
  it "should return true if the number goes evenly into the argument" do
12
20
  5.goes_into?(10).should be_true
@@ -26,8 +26,7 @@ describe Enumerable do
26
26
  describe "#heredoc" do
27
27
  test = expected = ""
28
28
 
29
- before do
30
- test = <<-EOS.heredoc
29
+ let(:test) do <<-EOS.heredoc
31
30
  This is a test of String#heredoc.
32
31
  This text should be left-aligned.
33
32
  This text is indented by four spaces.
@@ -36,8 +35,9 @@ describe Enumerable do
36
35
  now one space...
37
36
  Left-aligned again.
38
37
  EOS
38
+ end
39
39
 
40
- expected = <<EOS
40
+ let(:expected) do <<EOS
41
41
  This is a test of String#heredoc.
42
42
  This text should be left-aligned.
43
43
  This text is indented by four spaces.
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,2 @@
1
- # Tests if +method_a+ is an alias to +method_b+ in the class +cls+.
2
- def test_alias(cls, method_a, method_b)
3
- describe "##{method_a.to_s}" do
4
- it "should be an alias of ##{method_b.to_s}" do
5
- cls.instance_method(method_a).should === cls.instance_method(method_b)
6
- end
7
- end
8
- end
1
+ # Include all files in spec/support
2
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
@@ -0,0 +1,8 @@
1
+ # Tests if +method_a+ is an alias to +method_b+ in the class +cls+.
2
+ def test_alias(cls, method_a, method_b)
3
+ describe "##{method_a.to_s}" do
4
+ it "should be an alias of ##{method_b.to_s}" do
5
+ cls.instance_method(method_a).should === cls.instance_method(method_b)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,63 @@
1
+ NUMBER_FORMATS = {
2
+ -1 => "-1st",
3
+ -2 => "-2nd",
4
+ -3 => "-3rd",
5
+ -4 => "-4th",
6
+ -5 => "-5th",
7
+ -6 => "-6th",
8
+ -7 => "-7th",
9
+ -8 => "-8th",
10
+ -9 => "-9th",
11
+ -10 => "-10th",
12
+ -11 => "-11th",
13
+ -12 => "-12th",
14
+ -13 => "-13th",
15
+ -14 => "-14th",
16
+ -20 => "-20th",
17
+ -21 => "-21st",
18
+ -22 => "-22nd",
19
+ -23 => "-23rd",
20
+ -24 => "-24th",
21
+ -100 => "-100th",
22
+ -101 => "-101st",
23
+ -102 => "-102nd",
24
+ -103 => "-103rd",
25
+ -104 => "-104th",
26
+ -110 => "-110th",
27
+ -111 => "-111th",
28
+ -112 => "-112th",
29
+ -113 => "-113th",
30
+ -1000 => "-1000th",
31
+ -1001 => "-1001st",
32
+ 0 => "0th",
33
+ 1 => "1st",
34
+ 2 => "2nd",
35
+ 3 => "3rd",
36
+ 4 => "4th",
37
+ 5 => "5th",
38
+ 6 => "6th",
39
+ 7 => "7th",
40
+ 8 => "8th",
41
+ 9 => "9th",
42
+ 10 => "10th",
43
+ 11 => "11th",
44
+ 12 => "12th",
45
+ 13 => "13th",
46
+ 14 => "14th",
47
+ 20 => "20th",
48
+ 21 => "21st",
49
+ 22 => "22nd",
50
+ 23 => "23rd",
51
+ 24 => "24th",
52
+ 100 => "100th",
53
+ 101 => "101st",
54
+ 102 => "102nd",
55
+ 103 => "103rd",
56
+ 104 => "104th",
57
+ 110 => "110th",
58
+ 111 => "111th",
59
+ 112 => "112th",
60
+ 113 => "113th",
61
+ 1000 => "1000th",
62
+ 1001 => "1001st"
63
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1.1
4
+ version: '0.6'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fuubar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rake
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -100,11 +116,15 @@ files:
100
116
  - lib/nutella.rb
101
117
  - lib/nutella/version.rb
102
118
  - lib/nutella/input.rb
119
+ - lib/nutella/core_ext/integer/multiples.rb
120
+ - lib/nutella/core_ext/integer/format.rb
103
121
  - lib/nutella/core_ext/string.rb
104
122
  - lib/nutella/core_ext/integer.rb
105
123
  - lib/nutella/core_ext/hash.rb
106
124
  - lib/nutella/core_ext/enumerable.rb
107
125
  - lib/nutella/core_ext.rb
126
+ - spec/support/alias.rb
127
+ - spec/support/number_formats.rb
108
128
  - spec/nutella/core_ext/hash_spec.rb
109
129
  - spec/nutella/core_ext/enumerable_spec.rb
110
130
  - spec/nutella/core_ext/integer_spec.rb
@@ -136,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
156
  version: '0'
137
157
  segments:
138
158
  - 0
139
- hash: -759078437779235372
159
+ hash: 3508017811840001667
140
160
  requirements: []
141
161
  rubyforge_project:
142
162
  rubygems_version: 1.8.24
@@ -144,6 +164,8 @@ signing_key:
144
164
  specification_version: 3
145
165
  summary: Spread some Nutella on Ruby to sweeten up its functionality.
146
166
  test_files:
167
+ - spec/support/alias.rb
168
+ - spec/support/number_formats.rb
147
169
  - spec/nutella/core_ext/hash_spec.rb
148
170
  - spec/nutella/core_ext/enumerable_spec.rb
149
171
  - spec/nutella/core_ext/integer_spec.rb