utilities 0.0.20 → 0.0.21
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 +10 -2
- data/lib/utilities/object.rb +9 -0
- data/lib/utilities/utilities.rb +1 -1
- data/lib/version.rb +2 -2
- metadata +42 -22
- data/utilities-0.0.19.gem +0 -0
data/README.md
CHANGED
@@ -35,11 +35,11 @@ Usage
|
|
35
35
|
{:a=>1, :b=>2, :c=>3}.collect_first{|k,v| [k, v * 3] if v == 2 } #=> [:b, 6]
|
36
36
|
|
37
37
|
#### Hash
|
38
|
-
* collect_keys
|
38
|
+
* collect_keys, map_keys (passing true as a parameter will collect keys recursively)
|
39
39
|
|
40
40
|
{:a=>1, :b=>2, :c=>3}.collect_keys{|k| k.to_s.upcase } #=> {"A"=>1, "B"=>2, "C"=>3}
|
41
41
|
|
42
|
-
* collect_values
|
42
|
+
* collect_values, map_values (passing true as a parameter will collect values recursively)
|
43
43
|
|
44
44
|
{:a=>1, :b=>2, :c=>3}.collect_values{|v| v * -1 } #=> {:a=>-1, :b=>-2, :c=>-3}
|
45
45
|
|
@@ -85,6 +85,14 @@ Usage
|
|
85
85
|
|
86
86
|
48.percentage_of(50) #=> 96
|
87
87
|
|
88
|
+
#### Object
|
89
|
+
* attempt
|
90
|
+
|
91
|
+
Attempts to call a method on given object. If it fails (nil or NoMethodError), returns nil
|
92
|
+
|
93
|
+
nil.attempt(:something) #=> nil
|
94
|
+
"String".attempt(:wrong_method_name) #=> nil
|
95
|
+
|
88
96
|
#### String
|
89
97
|
* hour_to_float
|
90
98
|
|
data/lib/utilities/object.rb
CHANGED
@@ -6,4 +6,13 @@ class Object
|
|
6
6
|
enumerable.min <= self && self <= enumerable.max
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
# Attempts to call a method on given object. If it fails (nil or NoMethodError), returns nil
|
11
|
+
def attempt method, *args, &block
|
12
|
+
begin
|
13
|
+
self.try(method, *args, &block)
|
14
|
+
rescue NoMethodError
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
9
18
|
end
|
data/lib/utilities/utilities.rb
CHANGED
@@ -63,7 +63,7 @@ module Utilities
|
|
63
63
|
# Return the variance of self
|
64
64
|
def variance( population = false )
|
65
65
|
m = mean.to_f
|
66
|
-
collect{|v| (v -
|
66
|
+
collect{|v| (v - m).square }.to_stats.sum / (size - (population ? 0 : 1))
|
67
67
|
end
|
68
68
|
|
69
69
|
# Return the (sample|population) standard deviation of self
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilities
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 21
|
10
|
+
version: 0.0.21
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Christian Blais
|
9
14
|
- Guillaume Malette
|
10
15
|
- Louis-Mathieu Houle
|
11
16
|
autorequire:
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
|
-
|
19
|
+
|
20
|
+
date: 2011-10-11 00:00:00 -04:00
|
21
|
+
default_executable:
|
15
22
|
dependencies: []
|
16
|
-
|
17
|
-
|
18
|
-
email:
|
23
|
+
|
24
|
+
description: Few utilities include in all my projects, including a module for statistics, some to_date and to_time functions as well as intersection method for Range object.
|
25
|
+
email:
|
19
26
|
- christ.blais@gmail.com
|
20
27
|
- gmalette@gmail.com
|
21
28
|
executables: []
|
29
|
+
|
22
30
|
extensions: []
|
31
|
+
|
23
32
|
extra_rdoc_files: []
|
24
|
-
|
33
|
+
|
34
|
+
files:
|
25
35
|
- LICENSE
|
26
36
|
- README.md
|
27
37
|
- lib/utilities.rb
|
@@ -38,31 +48,41 @@ files:
|
|
38
48
|
- lib/utilities/utilities.rb
|
39
49
|
- lib/version.rb
|
40
50
|
- test/test_utilities.rb
|
41
|
-
- utilities-0.0.19.gem
|
42
51
|
- utilities.gemspec
|
52
|
+
has_rdoc: true
|
43
53
|
homepage: http://github.com/christianblais/utilities
|
44
54
|
licenses: []
|
55
|
+
|
45
56
|
post_install_message:
|
46
57
|
rdoc_options: []
|
47
|
-
|
58
|
+
|
59
|
+
require_paths:
|
48
60
|
- lib
|
49
61
|
- test
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
63
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
72
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
62
80
|
requirements: []
|
81
|
+
|
63
82
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.6.2
|
65
84
|
signing_key:
|
66
85
|
specification_version: 3
|
67
86
|
summary: Few utilities include in all my projects
|
68
87
|
test_files: []
|
88
|
+
|
data/utilities-0.0.19.gem
DELETED
Binary file
|