utilities 1.0.0 → 1.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.
@@ -8,6 +8,11 @@ class Numeric
8
8
  def square
9
9
  self * self
10
10
  end
11
+
12
+ # Return a clamped value between a minimum and maximum value
13
+ def clamp min, max
14
+ [min, self, max].sort[1]
15
+ end
11
16
 
12
17
  #Transform self to a string formatted time (HH:MM) Ex: 14.5 => “14:30“
13
18
  def hour_to_string delimiter = ':'
@@ -1,7 +1,7 @@
1
1
  module Utilities
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- BUILD = 0
4
+ BUILD = 1
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
7
7
  end
@@ -8,6 +8,12 @@ describe Array do
8
8
  [1,2,3,4,nil].numerics?.should == false
9
9
  [1,2,3,4,nil].numerics?(true).should == true
10
10
  end
11
+
12
+ it "#clamp should returns a clamped value between a minimum and maximum value" do
13
+ 1.clamp(2,5).should == 2
14
+ 8.clamp(2,5).should == 5
15
+ 3.clamp(2,5).should == 3
16
+ end
11
17
 
12
18
  it "#to_numerics should returns a new array with only numeric elements" do
13
19
  [].to_numerics.should == []
@@ -179,22 +185,7 @@ describe Utilities::Statistics do
179
185
  end
180
186
  end
181
187
 
182
- it "#first should returns the first element" do
183
- [].first.should == nil
184
- [4,3,5,1,2].first.should == 4
185
- end
186
-
187
- it "#last should returns the last element" do
188
- [].last.should == nil
189
- [4,3,5,1,2].last.should == 2
190
- end
191
-
192
- it "#size should returns the last element" do
193
- [].size.should == 0
194
- [4,3,5,1,2].size.should == 5
195
- end
196
-
197
- it "#sum should returns the last element" do
188
+ it "#sum should returns the sum of all elements" do
198
189
  [].sum.should == 0
199
190
  [4,3,5,1,2].sum.should == 15
200
191
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-22 00:00:00.000000000 Z
14
+ date: 2013-01-11 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: Few utilities include in all my projects, including a module for statistics,
17
17
  some to_date and to_time functions as well as intersection method for Range object.