nutella 0.9 → 0.10

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.
@@ -0,0 +1,12 @@
1
+ class Integer
2
+ # Returns an array of integers containing the digits of the integer. The
3
+ # <tt>"-"</tt> will be trimmed if the number is negative.
4
+ #
5
+ # 120.digits # => [1, 2, 0]
6
+ # -35.digits # => [3, 5]
7
+ #
8
+ # @return [Array] the digits of the number as integers
9
+ def digits
10
+ abs.to_s.chars.map &:to_i
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  class Integer
2
- # Checks whether the integer goes evenly into all of the arguments
2
+ # Checks whether the integer goes evenly into all of the arguments.
3
3
  #
4
4
  # @example Check if 3 goes into some numbers
5
5
  # 3.goes_into? 10 # => false
@@ -16,7 +16,7 @@ class Integer
16
16
  nums.all? { |n| (!zero? && n % self == 0) || n.zero? }
17
17
  end
18
18
 
19
- # Checks whether the integer goes evenly into any of the arguments
19
+ # Checks whether the integer goes evenly into any of the arguments.
20
20
  #
21
21
  # @example Check if 5 goes into every number in some sets of numbers
22
22
  # 5.goes_into_any? 10, 20 # => true
@@ -0,0 +1,15 @@
1
+ class Numeric
2
+ # Translates a percentage number to a decimal.
3
+ #
4
+ # 5.percent # => 0.05
5
+ # 20.percent # => 0.2
6
+ # 25.percent # => 0.25
7
+ # 125.percent # => 1.25
8
+ # 100.percent # => 1
9
+ # 200.percent # => 2
10
+ #
11
+ # @return [Numeric] the decimal for the percentage number
12
+ def percent
13
+ self / 100.0
14
+ end
15
+ end
@@ -1,4 +1,4 @@
1
1
  module Nutella
2
2
  # The current version of Nutella.
3
- VERSION = "0.9"
3
+ VERSION = "0.10"
4
4
  end
@@ -7,6 +7,20 @@ describe Integer do
7
7
  test_alias Integer, :divisible_by_any?, :multiple_of_any?
8
8
  end
9
9
 
10
+ describe "#digits" do
11
+ it "returns an array of the digits in the integer" do
12
+ (0..9).each { |n| n.digits.should == [n] }
13
+ 10.digits.should == [1, 0]
14
+ 349.digits.should == [3, 4, 9]
15
+ 1000.digits.should == [1, 0, 0, 0]
16
+ end
17
+
18
+ it "trims the '-' from negative numbers" do
19
+ -3.digits.should == [3]
20
+ -20.digits.should == [2, 0]
21
+ end
22
+ end
23
+
10
24
  describe "#ordinalize" do
11
25
  NUMBER_FORMATS.each do |cardinal, ordinal|
12
26
  it "returns the ordinal #{ordinal} for the integer #{cardinal}" do
@@ -9,6 +9,34 @@ describe Numeric do
9
9
  end
10
10
  end
11
11
 
12
+ describe "#percent" do
13
+ it "returns the percent for an integer" do
14
+ 5.percent.should == 0.05
15
+ 15.percent.should == 0.15
16
+ 50.percent.should == 0.5
17
+ 125.percent.should == 1.25
18
+ end
19
+
20
+ it "returns an integer for multiples of 100" do
21
+ 100.percent.should == 1
22
+ 500.percent.should == 5
23
+ end
24
+
25
+ it "returns the percent for a floating point" do
26
+ 0.5.percent.should == 0.005
27
+ 5.5.percent.should == 0.055
28
+ 10.5.percent.should == 0.105
29
+ end
30
+
31
+ it "returns an integer for floating point multiples of 100" do
32
+ 100.0.percent.should == 1
33
+ end
34
+
35
+ it "returns zero for 0" do
36
+ 0.percent.should be_zero
37
+ end
38
+ end
39
+
12
40
  describe "#sanity_check_min" do
13
41
  it "returns the parameter if the number is lower" do
14
42
  5.sanity_check_min(7).should == 7
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.9'
4
+ version: '0.10'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fuubar
@@ -119,6 +119,7 @@ files:
119
119
  - lib/nutella/core_ext/numeric.rb
120
120
  - lib/nutella/core_ext/integer/multiples.rb
121
121
  - lib/nutella/core_ext/integer/format.rb
122
+ - lib/nutella/core_ext/integer/digits.rb
122
123
  - lib/nutella/core_ext/object.rb
123
124
  - lib/nutella/core_ext/string.rb
124
125
  - lib/nutella/core_ext/file.rb
@@ -131,6 +132,7 @@ files:
131
132
  - lib/nutella/core_ext/hash.rb
132
133
  - lib/nutella/core_ext/object/blank.rb
133
134
  - lib/nutella/core_ext/object/aliases.rb
135
+ - lib/nutella/core_ext/numeric/percent.rb
134
136
  - lib/nutella/core_ext/numeric/sanity_check.rb
135
137
  - lib/nutella/core_ext/numeric/bytes.rb
136
138
  - lib/nutella/core_ext/enumerable.rb
@@ -172,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
174
  version: '0'
173
175
  segments:
174
176
  - 0
175
- hash: 830849630549550428
177
+ hash: -2105265980765175677
176
178
  requirements: []
177
179
  rubyforge_project:
178
180
  rubygems_version: 1.8.24