utilities 0.0.18 → 0.0.19
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/README.md +17 -0
- data/lib/utilities/array.rb +5 -0
- data/lib/utilities/string.rb +5 -0
- data/lib/version.rb +1 -1
- data/test/test_utilities.rb +19 -0
- metadata +3 -3
- data/utilities-0.0.17.gem +0 -0
data/README.md
CHANGED
@@ -25,6 +25,10 @@ Usage
|
|
25
25
|
|
26
26
|
[1,8,3].reverse_sort #=> [8,3,1]
|
27
27
|
|
28
|
+
* map_with
|
29
|
+
|
30
|
+
[1,2,3].map_with([4,5,6]){|i,j| i * j } #=> [4,10,18]
|
31
|
+
|
28
32
|
#### Enumerable
|
29
33
|
* collect_first
|
30
34
|
|
@@ -43,6 +47,10 @@ Usage
|
|
43
47
|
|
44
48
|
{"a"=>1, "b"=>2}.symbolize_keys #=> {:a=>1, :b=>2}
|
45
49
|
|
50
|
+
* stringify_keys
|
51
|
+
|
52
|
+
{:a=>1, :b=>2}.stringify_keys #=> {"a"=>1, "b"=>2}
|
53
|
+
|
46
54
|
#### Kernel
|
47
55
|
* raiser
|
48
56
|
|
@@ -77,6 +85,15 @@ Usage
|
|
77
85
|
|
78
86
|
48.percentage_of(50) #=> 96
|
79
87
|
|
88
|
+
#### String
|
89
|
+
* hour_to_float
|
90
|
+
|
91
|
+
"14:30".hour_to_float #=> 14.5
|
92
|
+
|
93
|
+
* float?
|
94
|
+
|
95
|
+
"123.456".float? #=> true
|
96
|
+
|
80
97
|
#### Utilities
|
81
98
|
* Statistics
|
82
99
|
|
data/lib/utilities/array.rb
CHANGED
@@ -25,6 +25,11 @@ class Array
|
|
25
25
|
end
|
26
26
|
alias_method :rsort!, :reverse_sort!
|
27
27
|
|
28
|
+
# Zip *args then call &block
|
29
|
+
def map_with( *args, &block )
|
30
|
+
zip(*args).map{|i| yield i }
|
31
|
+
end
|
32
|
+
|
28
33
|
# Returns a copy of self that includes the Statistics methods
|
29
34
|
def to_stat
|
30
35
|
dup.to_stat!
|
data/lib/utilities/string.rb
CHANGED
data/lib/version.rb
CHANGED
data/test/test_utilities.rb
CHANGED
@@ -21,6 +21,15 @@ describe Array do
|
|
21
21
|
["f", "3", "z"].reverse_sort.should == ["z", "f", "3"]
|
22
22
|
end
|
23
23
|
|
24
|
+
it "#map_with should zip *args together and yield &block on them" do
|
25
|
+
a = [1,2,3]
|
26
|
+
b = [4,5,6]
|
27
|
+
c = [7,8,9]
|
28
|
+
|
29
|
+
a.map_with(b){ |i,j| i*j }.should == [4,10,18]
|
30
|
+
a.map_with(b, c){ |i,j,k| i + j + k }.should == [12,15,18]
|
31
|
+
end
|
32
|
+
|
24
33
|
it "#to_stat should extends given array with module Utilities::Statistics" do
|
25
34
|
[].methods.include?(:statistics).should == false
|
26
35
|
[].to_stat.methods.include?(:statistics).should == true
|
@@ -135,6 +144,16 @@ describe String do
|
|
135
144
|
"14:30".hour_to_float.should == 14.5
|
136
145
|
"03h12".hour_to_float('h').should == 3.2
|
137
146
|
end
|
147
|
+
|
148
|
+
it "#float? check if self is a valid float or not" do
|
149
|
+
"123.456".float?.should == true
|
150
|
+
"1".float?.should == true
|
151
|
+
".456".float?.should == true
|
152
|
+
"hello 123.456 world".float?.should == false
|
153
|
+
"hello world".float?.should == false
|
154
|
+
"123.456 hello".float?.should == false
|
155
|
+
"hello 123.456".float?.should == false
|
156
|
+
end
|
138
157
|
end
|
139
158
|
|
140
159
|
describe Utilities::Statistics do
|
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: 0.0.
|
4
|
+
version: 0.0.19
|
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: 2011-09-
|
14
|
+
date: 2011-09-23 00:00:00.000000000Z
|
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.
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- lib/utilities/utilities.rb
|
39
39
|
- lib/version.rb
|
40
40
|
- test/test_utilities.rb
|
41
|
-
- utilities-0.0.
|
41
|
+
- utilities-0.0.19.gem
|
42
42
|
- utilities.gemspec
|
43
43
|
homepage: http://github.com/christianblais/utilities
|
44
44
|
licenses: []
|
data/utilities-0.0.17.gem
DELETED
Binary file
|