active_object 2.3.0 → 2.3.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/README.md +5 -0
- data/lib/active_object/array.rb +12 -12
- data/lib/active_object/date.rb +6 -0
- data/lib/active_object/enumerable.rb +23 -23
- data/lib/active_object/hash.rb +2 -2
- data/lib/active_object/numeric.rb +3 -3
- data/lib/active_object/string.rb +5 -5
- data/lib/active_object/time.rb +6 -0
- data/lib/active_object/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: 62f60060b5fe65de31fdf1458f844ca30449f238
|
4
|
+
data.tar.gz: b250d0f529558f2a8f3587f64c45518b8c4dac50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5d9eb11fa150a505a773b33908c15588fe6edf34ad6840c1e109a086e5fa89b52a20a3adcdf66a266d1902879dc1b2064eaac196ff450fb925c2075b299bf00
|
7
|
+
data.tar.gz: 97cfea106f651c78915959675a1b61a845e9073b0fe4ea4f661ab1ad90360f421277133fce5b0118460348c676ce14ab4d90c3f78d701a56c640b22a9526bfa8
|
data/README.md
CHANGED
@@ -1767,6 +1767,11 @@ Time.now.stamp(:datetime) #=> "January 09, 2014 02:31 pm"
|
|
1767
1767
|
| Month - digits blank-padded | `:month_blank` | %a | ( 1..12) |
|
1768
1768
|
| Month - name | `:month_name` | %A | January |
|
1769
1769
|
| Month - name abbreviated | `:month_name_abbr` | %a | Jan |
|
1770
|
+
| Month - digits zero-padded | `:month_year` or `:month_padded_year` | %A | (01..12) 2015 |
|
1771
|
+
| Month - digits unpadded | `:month_unpadded_year` | %a | (1..12) 2015 |
|
1772
|
+
| Month - digits blank-padded | `:month_blank_year` | %a | ( 1..12) 2015 |
|
1773
|
+
| Month - name | `:month_name_year` | %A | January 2015 |
|
1774
|
+
| Month - name abbreviated | `:month_name_abbr_year` | %a | Jan 2015 |
|
1770
1775
|
| Weekday - digits zero-padded | `:weekday_padded` | %A | (01..31) |
|
1771
1776
|
| Weekday - digits unpadded | `:weekday_unpadded` | %a | (1..31) |
|
1772
1777
|
| Weekday - digits blank-padded | `:weekday_blank` | %a | ( 1..31) |
|
data/lib/active_object/array.rb
CHANGED
@@ -3,13 +3,13 @@ class Array
|
|
3
3
|
def after(value)
|
4
4
|
return(nil) unless include?(value)
|
5
5
|
|
6
|
-
self[(index(value).to_i + 1) %
|
6
|
+
self[(index(value).to_i + 1) % length]
|
7
7
|
end
|
8
8
|
|
9
9
|
def before(value)
|
10
10
|
return(nil) unless include?(value)
|
11
11
|
|
12
|
-
self[(index(value).to_i - 1) %
|
12
|
+
self[(index(value).to_i - 1) % length]
|
13
13
|
end
|
14
14
|
|
15
15
|
def delete_first
|
@@ -43,23 +43,23 @@ class Array
|
|
43
43
|
|
44
44
|
unless defined?(Rails)
|
45
45
|
def from(position)
|
46
|
-
self[position,
|
46
|
+
self[position, length] || []
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def groups(number)
|
51
51
|
return([]) if number <= 0
|
52
52
|
|
53
|
-
n, r =
|
53
|
+
n, r = length.divmod(number)
|
54
54
|
collection = (0..(n - 1)).collect { |i| self[(i * number), number] }
|
55
55
|
r > 0 ? collection << self[-r, r] : collection
|
56
56
|
end
|
57
57
|
|
58
58
|
unless defined?(Rails)
|
59
59
|
def in_groups(number, fill_with=nil)
|
60
|
-
|
61
|
-
division =
|
62
|
-
modulo =
|
60
|
+
collection_length = length
|
61
|
+
division = collection_length.div(number)
|
62
|
+
modulo = collection_length % number
|
63
63
|
|
64
64
|
collection = []
|
65
65
|
start = 0
|
@@ -78,13 +78,13 @@ class Array
|
|
78
78
|
def in_groups_of(number, fill_with=nil)
|
79
79
|
if number.to_i <= 0
|
80
80
|
raise ArgumentError,
|
81
|
-
"Group
|
81
|
+
"Group length must be a positive integer, was #{number.inspect}"
|
82
82
|
end
|
83
83
|
|
84
84
|
if fill_with == false
|
85
85
|
collection = self
|
86
86
|
else
|
87
|
-
padding = (number -
|
87
|
+
padding = (number - length % number) % number
|
88
88
|
collection = dup.concat(Array.new(padding, fill_with))
|
89
89
|
end
|
90
90
|
|
@@ -110,7 +110,7 @@ class Array
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def sample!
|
113
|
-
delete_at(Random.rand(
|
113
|
+
delete_at(Random.rand(length - 1))
|
114
114
|
end
|
115
115
|
|
116
116
|
unless defined?(Rails)
|
@@ -128,7 +128,7 @@ class Array
|
|
128
128
|
arr.shift
|
129
129
|
results << []
|
130
130
|
else
|
131
|
-
results.last.concat(arr.shift(arr.
|
131
|
+
results.last.concat(arr.shift(arr.length))
|
132
132
|
end
|
133
133
|
end
|
134
134
|
results
|
@@ -161,7 +161,7 @@ class Array
|
|
161
161
|
}
|
162
162
|
options = default_connectors.merge!(options)
|
163
163
|
|
164
|
-
case
|
164
|
+
case length
|
165
165
|
when 0
|
166
166
|
''
|
167
167
|
when 1
|
data/lib/active_object/date.rb
CHANGED
@@ -62,6 +62,12 @@ class Date
|
|
62
62
|
month_blank: '%_m',
|
63
63
|
month_name: '%B',
|
64
64
|
month_name_abbr: '%b',
|
65
|
+
month_year: '%m %y',
|
66
|
+
month_padded_year: '%m %y',
|
67
|
+
month_unpadded_year: '%-m %y',
|
68
|
+
month_blank_year: '%_m %y',
|
69
|
+
month_name_year: '%B %y',
|
70
|
+
month_name_abbr_year: '%b %y',
|
65
71
|
weekday: '%d',
|
66
72
|
weekday_padded: '%d',
|
67
73
|
weekday_unpadded: '%-d',
|
@@ -31,11 +31,11 @@ module Enumerable
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def drop_last(n)
|
34
|
-
|
34
|
+
collection_length = to_a.length
|
35
35
|
|
36
|
-
return(self) if n >
|
36
|
+
return(self) if n > collection_length
|
37
37
|
|
38
|
-
self[0...(
|
38
|
+
self[0...(collection_length - n)]
|
39
39
|
end
|
40
40
|
|
41
41
|
def drop_last_if
|
@@ -96,40 +96,40 @@ module Enumerable
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def max(identity=0)
|
99
|
-
|
99
|
+
self.length > 0 ? sort.last : identity
|
100
100
|
end
|
101
101
|
|
102
102
|
def min(identity=0)
|
103
|
-
|
103
|
+
self.length > 0 ? sort.first : identity
|
104
104
|
end
|
105
105
|
|
106
106
|
def mean(identity=0)
|
107
|
-
return(identity) unless
|
107
|
+
return(identity) unless length > 0
|
108
108
|
|
109
|
-
|
110
|
-
sum.to_f /
|
109
|
+
collection_length = length
|
110
|
+
sum.to_f / collection_length.to_f
|
111
111
|
end
|
112
112
|
|
113
113
|
def median(identity=0)
|
114
|
-
|
114
|
+
collection_length = length.to_f
|
115
115
|
collection_sorted = sort
|
116
116
|
|
117
|
-
return(identity) unless
|
117
|
+
return(identity) unless collection_length > 0
|
118
118
|
|
119
|
-
if (
|
120
|
-
(collection_sorted[(
|
119
|
+
if (collection_length % 2).zero?
|
120
|
+
(collection_sorted[(collection_length / 2.0) -1.0] + collection_sorted[collection_length / 2.0]) / 2.0
|
121
121
|
else
|
122
|
-
collection_sorted[
|
122
|
+
collection_sorted[collection_length / 2.0]
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
def mode(identity=0)
|
127
|
-
return(identity) unless
|
127
|
+
return(identity) unless length > 0
|
128
128
|
|
129
129
|
frequency_distribution = inject(Hash.new(0)) { |h, v| h[v] += 1; h }
|
130
130
|
frequency_top_two = frequency_distribution.sort { |k, v| v[1] <=> k[1] }.take(2)
|
131
131
|
|
132
|
-
if frequency_top_two.
|
132
|
+
if frequency_top_two.length == 1
|
133
133
|
frequency_top_two.first.first
|
134
134
|
elsif frequency_top_two.first.last == frequency_top_two.last.last
|
135
135
|
nil
|
@@ -147,7 +147,7 @@ module Enumerable
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def range(identity=0)
|
150
|
-
return(identity) unless
|
150
|
+
return(identity) unless length > 0
|
151
151
|
|
152
152
|
collection_sorted = sort
|
153
153
|
collection_sorted.last - collection_sorted.first
|
@@ -160,7 +160,7 @@ module Enumerable
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def standard_deviation(identity=0)
|
163
|
-
return(identity) if
|
163
|
+
return(identity) if length < 2
|
164
164
|
|
165
165
|
Math.sqrt(variance)
|
166
166
|
end
|
@@ -176,11 +176,11 @@ module Enumerable
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def take_last(n)
|
179
|
-
|
179
|
+
collection_length = to_a.length
|
180
180
|
|
181
|
-
return(self) if n >
|
181
|
+
return(self) if n > collection_length
|
182
182
|
|
183
|
-
self[(
|
183
|
+
self[(collection_length - n)..-1]
|
184
184
|
end
|
185
185
|
|
186
186
|
def take_last_if
|
@@ -192,12 +192,12 @@ module Enumerable
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def variance(identity=0)
|
195
|
-
|
195
|
+
collection_length = length
|
196
196
|
|
197
|
-
return(identity) if
|
197
|
+
return(identity) if collection_length <= 1
|
198
198
|
|
199
199
|
sum = inject(0.0) { |s,v| s + (v - mean) ** 2.0 }
|
200
|
-
sum.to_f / (
|
200
|
+
sum.to_f / (collection_length.to_f - 1.0)
|
201
201
|
end
|
202
202
|
|
203
203
|
end
|
data/lib/active_object/hash.rb
CHANGED
@@ -108,7 +108,7 @@ class Hash
|
|
108
108
|
|
109
109
|
def sample_key
|
110
110
|
hash_keys = keys
|
111
|
-
hash_keys.at(Random.rand(hash_keys.
|
111
|
+
hash_keys.at(Random.rand(hash_keys.length - 1))
|
112
112
|
end
|
113
113
|
|
114
114
|
def sample_key!
|
@@ -128,7 +128,7 @@ class Hash
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def shuffle
|
131
|
-
Hash[to_a.sample(
|
131
|
+
Hash[to_a.sample(length)]
|
132
132
|
end
|
133
133
|
|
134
134
|
def shuffle!
|
@@ -308,9 +308,9 @@ class Numeric
|
|
308
308
|
string = to_s
|
309
309
|
|
310
310
|
string << separator unless string.include?(separator)
|
311
|
-
ljust_count = string.split(separator).first.
|
311
|
+
ljust_count = string.split(separator).first.length
|
312
312
|
ljust_count += (string.count(separator) + precision) if precision > 0
|
313
|
-
num_count = string.
|
313
|
+
num_count = string.length
|
314
314
|
ljust_count >= num_count ? string.ljust(ljust_count, pad_number.to_s) : string[0..(ljust_count - 1)]
|
315
315
|
end
|
316
316
|
|
@@ -464,7 +464,7 @@ class Numeric
|
|
464
464
|
end
|
465
465
|
|
466
466
|
def to_nearest_value(values=[])
|
467
|
-
return(self) if values.
|
467
|
+
return(self) if values.length.zero?
|
468
468
|
|
469
469
|
value = values.first
|
470
470
|
difference = (self - value).abs
|
data/lib/active_object/string.rb
CHANGED
@@ -100,7 +100,7 @@ class String
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def ellipsize(ellipsize_at, options={})
|
103
|
-
return(self)if
|
103
|
+
return(self)if length <= ellipsize_at
|
104
104
|
|
105
105
|
separator = options.fetch(:separator, '...'.freeze)
|
106
106
|
offset = options.fetch(:offset, 4)
|
@@ -118,7 +118,7 @@ class String
|
|
118
118
|
def first(limit=1)
|
119
119
|
return(''.freeze) if limit.zero?
|
120
120
|
|
121
|
-
limit >=
|
121
|
+
limit >= length ? self.dup : to(limit - 1)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -163,7 +163,7 @@ class String
|
|
163
163
|
def last(limit=1)
|
164
164
|
return(''.freeze) if limit.zero?
|
165
165
|
|
166
|
-
limit >=
|
166
|
+
limit >= length ? self.dup : from(-limit)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
@@ -305,10 +305,10 @@ class String
|
|
305
305
|
|
306
306
|
unless defined?(Rails)
|
307
307
|
def truncate(truncate_at, options={})
|
308
|
-
return(dup) unless
|
308
|
+
return(dup) unless length > truncate_at
|
309
309
|
|
310
310
|
omission = options.fetch(:omission, '...'.freeze)
|
311
|
-
size_with_room_for_omission = truncate_at - omission.
|
311
|
+
size_with_room_for_omission = truncate_at - omission.length
|
312
312
|
|
313
313
|
stop = if options.fetch(:separator, false)
|
314
314
|
rindex(options.fetch(:separator, ''.freeze), size_with_room_for_omission) || size_with_room_for_omission
|
data/lib/active_object/time.rb
CHANGED
@@ -86,6 +86,12 @@ class Time
|
|
86
86
|
month_blank: '%_m',
|
87
87
|
month_name: '%B',
|
88
88
|
month_name_abbr: '%b',
|
89
|
+
month_year: '%m %y',
|
90
|
+
month_padded_year: '%m %y',
|
91
|
+
month_unpadded_year: '%-m %y',
|
92
|
+
month_blank_year: '%_m %y',
|
93
|
+
month_name_year: '%B %y',
|
94
|
+
month_name_abbr_year: '%b %y',
|
89
95
|
weekday: '%d',
|
90
96
|
weekday_padded: '%d',
|
91
97
|
weekday_unpadded: '%-d',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.0
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Gem for commonly used ruby object helpers.
|