flash_extensions 3.1.0 → 3.1.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.
- checksums.yaml +4 -4
- data/lib/flash_extensions/extensions/array_extension.rb +1 -1
- data/lib/flash_extensions/extensions/enumerable_extension.rb +15 -23
- data/lib/flash_extensions/extensions/numeric_extension.rb +14 -14
- data/lib/flash_extensions/extensions/object_extension.rb +1 -1
- data/lib/flash_extensions/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4a7aafeb611b94c20ec6deecf5e604714e55482
|
4
|
+
data.tar.gz: b5d57365ddd985af4abebde381662d624b90fb59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d40db1ddc4db820c4364e1ac382e1c2786d199d0ea4921f007a27cf364ff59bae43fc613277562bbba6d74478d649e8c374ba7a0f6c5b6123d78c7b89ad54d9e
|
7
|
+
data.tar.gz: 9fd19ad1ee7ba42da595e539fc214b57b98cad4d9a5650f8a57d3267d16e57f842007dbbe28c9e821d4daa45ac7131e3e50978f2a89db004bbf38ef13119464c
|
@@ -2,7 +2,7 @@ module Enumerable
|
|
2
2
|
|
3
3
|
unless method_defined?(:sum)
|
4
4
|
def sum(identity=0)
|
5
|
-
inject
|
5
|
+
inject(:+) || identity
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -16,10 +16,10 @@ module Enumerable
|
|
16
16
|
def drop_last_while
|
17
17
|
return to_enum(:drop_last_while) unless block_given?
|
18
18
|
|
19
|
-
result
|
19
|
+
result = []
|
20
20
|
dropping = true
|
21
|
-
reverse_each do |
|
22
|
-
result.unshift(
|
21
|
+
reverse_each do |value|
|
22
|
+
result.unshift(value) unless dropping &&= yield(value)
|
23
23
|
end
|
24
24
|
result
|
25
25
|
end
|
@@ -29,15 +29,11 @@ module Enumerable
|
|
29
29
|
|
30
30
|
if block_given?
|
31
31
|
each do |*o|
|
32
|
-
if yield(*o)
|
33
|
-
found_count += 1
|
34
|
-
end
|
32
|
+
found_count += 1 if yield(*o)
|
35
33
|
end
|
36
34
|
else
|
37
35
|
each do |o|
|
38
|
-
if o
|
39
|
-
found_count += 1
|
40
|
-
end
|
36
|
+
found_count += 1 if o
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
@@ -58,7 +54,7 @@ module Enumerable
|
|
58
54
|
|
59
55
|
def mean(identity=0)
|
60
56
|
collection_size = size
|
61
|
-
collection_size > 0 ? inject(
|
57
|
+
collection_size > 0 ? inject(:+) / collection_size.to_f : identity
|
62
58
|
end
|
63
59
|
|
64
60
|
def median(identity=0)
|
@@ -79,14 +75,14 @@ module Enumerable
|
|
79
75
|
def mode(identity=0)
|
80
76
|
if size > 0
|
81
77
|
frequency_distribution = inject(Hash.new(0)) { |h, v| h[v] += 1; h }
|
82
|
-
|
78
|
+
frequency_top_2 = frequency_distribution.sort { |a, b| b[1] <=> a[1] }.take(2)
|
83
79
|
|
84
|
-
if
|
85
|
-
|
86
|
-
elsif
|
80
|
+
if frequency_top_2.length == 1
|
81
|
+
frequency_top_2.first.first
|
82
|
+
elsif frequency_top_2.first.last == frequency_top_2.last.last
|
87
83
|
nil
|
88
84
|
else
|
89
|
-
|
85
|
+
frequency_top_2.first.first
|
90
86
|
end
|
91
87
|
else
|
92
88
|
identity
|
@@ -103,15 +99,11 @@ module Enumerable
|
|
103
99
|
|
104
100
|
if block_given?
|
105
101
|
each do |*o|
|
106
|
-
if yield(*o)
|
107
|
-
found_count += 1
|
108
|
-
end
|
102
|
+
found_count += 1 if yield(*o)
|
109
103
|
end
|
110
104
|
else
|
111
105
|
each do |o|
|
112
|
-
if o
|
113
|
-
found_count += 1
|
114
|
-
end
|
106
|
+
found_count += 1 if o
|
115
107
|
end
|
116
108
|
end
|
117
109
|
|
@@ -129,7 +121,7 @@ module Enumerable
|
|
129
121
|
return to_enum(:take_last_while) unless block_given?
|
130
122
|
|
131
123
|
result = []
|
132
|
-
reverse_each { |e| yield(e) ? result.unshift(e) : break
|
124
|
+
reverse_each { |e| yield(e) ? result.unshift(e) : break }
|
133
125
|
result
|
134
126
|
end
|
135
127
|
|
@@ -17,7 +17,7 @@ class Numeric
|
|
17
17
|
def to_byte(from=:b, to=:kb)
|
18
18
|
scalers = { b: 1, kb: 1024 ** 1, mb: 1024 ** 2, gb: 1024 ** 3, tb: 1024 ** 4, pb: 1024 ** 5, eb: 1024 ** 6 }
|
19
19
|
|
20
|
-
|
20
|
+
to_f * scalers[from] / scalers[to]
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_length(from=:mm, to=:in)
|
@@ -35,15 +35,15 @@ class Numeric
|
|
35
35
|
self
|
36
36
|
when :mm, :cm, :m, :km
|
37
37
|
if [:in, :ft, :yd, :mi, :nm].include?(from)
|
38
|
-
|
38
|
+
to_f * imperical_scalers[from] * imperical_scalers[to]
|
39
39
|
else
|
40
|
-
|
40
|
+
to_f * metric_scalers[from] / metric_scalers[to]
|
41
41
|
end
|
42
42
|
when :in, :ft, :yd, :mi, :nm
|
43
43
|
if [:mm, :cm, :m, :km].include?(from)
|
44
|
-
|
44
|
+
to_f * metric_scalers[from] * metric_scalers[to]
|
45
45
|
else
|
46
|
-
|
46
|
+
to_f * imperical_scalers[from] / imperical_scalers[to]
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -53,14 +53,14 @@ class Numeric
|
|
53
53
|
when from
|
54
54
|
self
|
55
55
|
when :c, :celsius
|
56
|
-
(
|
56
|
+
(to_f - 32) * 5 / 9
|
57
57
|
when :f, :fahrenheit
|
58
|
-
(
|
58
|
+
(to_f * 9 / 5) + 32
|
59
59
|
when :k, :kelvin
|
60
60
|
if [:c, :celsius].include?(from)
|
61
|
-
|
61
|
+
to_f + 273.15
|
62
62
|
else
|
63
|
-
((
|
63
|
+
((to_f - 32) * 5 / 9) + 273.15
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -68,7 +68,7 @@ class Numeric
|
|
68
68
|
def to_time_unit(from=:sec, to=:min)
|
69
69
|
scalers = { sec: 1, min: 60 ** 1, hr: 60 ** 2, day: (60 ** 2) * 24, yr: (60 ** 2) * 24 * 365 }
|
70
70
|
|
71
|
-
|
71
|
+
to_f * scalers[from] / scalers[to]
|
72
72
|
end
|
73
73
|
|
74
74
|
def to_weight(from=:g, to=:oz)
|
@@ -86,15 +86,15 @@ class Numeric
|
|
86
86
|
self
|
87
87
|
when :mg, :cg, :g, :kg, :mt
|
88
88
|
if [:oz, :lb, :tn].include?(from)
|
89
|
-
|
89
|
+
to_f * imperical_scalers[from] * imperical_scalers[to]
|
90
90
|
else
|
91
|
-
|
91
|
+
to_f * metric_scalers[from] / metric_scalers[to]
|
92
92
|
end
|
93
93
|
when :oz, :lb, :tn
|
94
94
|
if [:mg, :cg, :g, :kg, :mt].include?(from)
|
95
|
-
|
95
|
+
to_f * metric_scalers[from] * metric_scalers[to]
|
96
96
|
else
|
97
|
-
|
97
|
+
to_f * imperical_scalers[from] / imperical_scalers[to]
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flash_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.4.
|
122
|
+
rubygems_version: 2.4.4
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Commonly used object helpers
|