active_object 5.7.0 → 5.8.0
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/active_object/array.rb +9 -9
- data/lib/active_object/date.rb +1 -4
- data/lib/active_object/enumerable.rb +13 -14
- data/lib/active_object/hash.rb +5 -5
- data/lib/active_object/integer.rb +12 -1
- data/lib/active_object/kernel.rb +5 -4
- data/lib/active_object/numeric.rb +30 -25
- data/lib/active_object/object.rb +6 -2
- data/lib/active_object/range.rb +4 -6
- data/lib/active_object/string.rb +4 -5
- data/lib/active_object/time.rb +1 -1
- data/lib/active_object/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c6fc484928254173ce44e6b9f7c4a7ff73a0711f9890f9976f394bc8db1e85
|
4
|
+
data.tar.gz: 2e99c34f428b114a6d776f7426af8399643f0401994b69b4619ca577a601a402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c5e925327ee1aaa043b56dd0c082bbb28bcfe63f8e2dc12ba7c06156744e134723fdb329f1d6e0425ec33688c764f7e3cd8d43aae8bdca25080f307bbe9a629
|
7
|
+
data.tar.gz: c370ee668f6d8edbe3677648bd182666618289b75a0a78ea587e7d914c3d36fec6dbf214c4ca4a23f6b9844f52ebe3538f9715bb6aef4fec9cb1825cea467ddd
|
data/lib/active_object/array.rb
CHANGED
@@ -32,9 +32,7 @@ module ActiveObject
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def delete_values(*args)
|
35
|
-
|
36
|
-
args.each { |val| result << delete(val) }
|
37
|
-
result
|
35
|
+
args.each_with_object([]) { |val, results| results << delete(val) }
|
38
36
|
end
|
39
37
|
|
40
38
|
def demote(value)
|
@@ -120,7 +118,6 @@ module ActiveObject
|
|
120
118
|
end
|
121
119
|
|
122
120
|
sliced_collection = collection.each_slice(number)
|
123
|
-
|
124
121
|
block_given? ? sliced_collection { |val| yield(val) } : sliced_collection.to_a
|
125
122
|
end
|
126
123
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
@@ -146,7 +143,9 @@ module ActiveObject
|
|
146
143
|
|
147
144
|
def position(value)
|
148
145
|
idx = index(value)
|
149
|
-
|
146
|
+
return if idx.nil?
|
147
|
+
|
148
|
+
idx + 1
|
150
149
|
end
|
151
150
|
|
152
151
|
def positions(value)
|
@@ -180,7 +179,9 @@ module ActiveObject
|
|
180
179
|
|
181
180
|
def rposition(value)
|
182
181
|
idx = rindex(value)
|
183
|
-
|
182
|
+
return if idx.nil?
|
183
|
+
|
184
|
+
idx + 1
|
184
185
|
end
|
185
186
|
|
186
187
|
def sample!
|
@@ -226,12 +227,11 @@ module ActiveObject
|
|
226
227
|
|
227
228
|
# rubocop:disable Metrics/MethodLength
|
228
229
|
def to_sentence(options = {})
|
229
|
-
|
230
|
+
options = {
|
230
231
|
words_connector: ', ',
|
231
232
|
two_words_connector: ' and ',
|
232
233
|
last_word_connector: ', and '
|
233
|
-
}
|
234
|
-
options = default_connectors.merge!(options)
|
234
|
+
}.merge!(options)
|
235
235
|
|
236
236
|
case length
|
237
237
|
when 0
|
data/lib/active_object/date.rb
CHANGED
@@ -152,10 +152,7 @@ module ActiveObject
|
|
152
152
|
def format(string)
|
153
153
|
delimiters = string.scan(/\W+/)
|
154
154
|
formatters = string.scan(/[a-z0-9_]+/i)
|
155
|
-
|
156
|
-
string = formatters.map do |unit|
|
157
|
-
"%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift || ''}"
|
158
|
-
end
|
155
|
+
string = formatters.map { |unit| "%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift}" }
|
159
156
|
|
160
157
|
strftime(string.join)
|
161
158
|
end
|
@@ -55,12 +55,10 @@ if ActiveObject.configuration.autoload_enumerable
|
|
55
55
|
|
56
56
|
# rubocop:disable Lint/UnusedMethodArgument
|
57
57
|
def cluster(&block)
|
58
|
-
|
59
|
-
|
60
|
-
last_res
|
61
|
-
last_res && (yield(ele) == yield(last_res.last)) ? last_res << ele : result << [ele]
|
58
|
+
each_with_object([]) do |ele, results|
|
59
|
+
last_res = results.last
|
60
|
+
last_res && (yield(ele) == yield(last_res.last)) ? last_res << ele : results << [ele]
|
62
61
|
end
|
63
|
-
result
|
64
62
|
end
|
65
63
|
# rubocop:enable Lint/UnusedMethodArgument
|
66
64
|
|
@@ -101,23 +99,23 @@ if ActiveObject.configuration.autoload_enumerable
|
|
101
99
|
end
|
102
100
|
|
103
101
|
def drop_last_if
|
104
|
-
return
|
102
|
+
return to_enum(:drop_last_if) unless block_given?
|
105
103
|
|
106
|
-
result = []
|
107
104
|
dropping = true
|
108
|
-
|
109
|
-
|
110
|
-
end
|
105
|
+
result = []
|
106
|
+
reverse_each { |val| result.unshift(val) unless dropping &&= yield(val) }
|
111
107
|
result
|
112
108
|
end
|
113
109
|
|
114
110
|
def exactly?(num)
|
115
111
|
found_count = 0
|
112
|
+
|
116
113
|
if block_given?
|
117
114
|
each { |*opt| found_count += 1 if yield(*opt) }
|
118
115
|
else
|
119
116
|
each { |opt| found_count += 1 if opt }
|
120
117
|
end
|
118
|
+
|
121
119
|
found_count > num ? false : num == found_count
|
122
120
|
end
|
123
121
|
|
@@ -171,6 +169,7 @@ if ActiveObject.configuration.autoload_enumerable
|
|
171
169
|
|
172
170
|
def many?
|
173
171
|
found_count = 0
|
172
|
+
|
174
173
|
if block_given?
|
175
174
|
any? do |val|
|
176
175
|
found_count += 1 if yield val
|
@@ -193,7 +192,6 @@ if ActiveObject.configuration.autoload_enumerable
|
|
193
192
|
def median(identity = 0)
|
194
193
|
collection_length = length.to_f
|
195
194
|
collection_sorted = sort
|
196
|
-
|
197
195
|
return(identity) unless collection_length > 0.0
|
198
196
|
|
199
197
|
half_collection = collection_length / 2.0
|
@@ -213,7 +211,6 @@ if ActiveObject.configuration.autoload_enumerable
|
|
213
211
|
frequency_distribution = each_with_object(::Hash.new(0)) { |val, hsh| hsh[val] += 1 }
|
214
212
|
frequency_top_two = frequency_distribution.sort_by { |_, val| -val }.take(2)
|
215
213
|
top_two_first = frequency_top_two.first
|
216
|
-
|
217
214
|
return if frequency_top_two.length != 1 && top_two_first.last == frequency_top_two.last.last
|
218
215
|
|
219
216
|
top_two_first.first
|
@@ -260,6 +257,7 @@ if ActiveObject.configuration.autoload_enumerable
|
|
260
257
|
|
261
258
|
def reject_outliers
|
262
259
|
cz = critical_zscore
|
260
|
+
|
263
261
|
reject { |value| zscore(value) > cz }
|
264
262
|
end
|
265
263
|
|
@@ -269,16 +267,19 @@ if ActiveObject.configuration.autoload_enumerable
|
|
269
267
|
|
270
268
|
def select_outliers
|
271
269
|
cz = critical_zscore
|
270
|
+
|
272
271
|
select { |value| zscore(value) > cz }
|
273
272
|
end
|
274
273
|
|
275
274
|
def several?
|
276
275
|
found_count = 0
|
276
|
+
|
277
277
|
if block_given?
|
278
278
|
each { |*opt| found_count += 1 if yield(*opt) }
|
279
279
|
else
|
280
280
|
each { |opt| found_count += 1 if opt }
|
281
281
|
end
|
282
|
+
|
282
283
|
found_count > 1
|
283
284
|
end
|
284
285
|
|
@@ -298,7 +299,6 @@ if ActiveObject.configuration.autoload_enumerable
|
|
298
299
|
|
299
300
|
def take_last(num)
|
300
301
|
collection_length = to_a.length
|
301
|
-
|
302
302
|
return self if num > collection_length
|
303
303
|
|
304
304
|
self[(collection_length - num)..-1]
|
@@ -314,7 +314,6 @@ if ActiveObject.configuration.autoload_enumerable
|
|
314
314
|
|
315
315
|
def variance(identity = 0)
|
316
316
|
collection_length = length
|
317
|
-
|
318
317
|
return identity if collection_length <= 1
|
319
318
|
|
320
319
|
total = inject(0.0) { |sum, val| sum + (val - mean)**2.0 }
|
data/lib/active_object/hash.rb
CHANGED
@@ -33,13 +33,13 @@ module ActiveObject
|
|
33
33
|
|
34
34
|
# rubocop:disable Lint/UnusedMethodArgument
|
35
35
|
def collect_keys(&block)
|
36
|
-
return
|
36
|
+
return enum_for(:collect_keys) unless block_given?
|
37
37
|
|
38
38
|
collect { |key, _| yield(key) }
|
39
39
|
end
|
40
40
|
|
41
41
|
def collect_values(&block)
|
42
|
-
return
|
42
|
+
return enum_for(:collect_values) unless block_given?
|
43
43
|
|
44
44
|
collect { |_, val| yield(val) }
|
45
45
|
end
|
@@ -216,7 +216,7 @@ module ActiveObject
|
|
216
216
|
|
217
217
|
def slice(*keys)
|
218
218
|
keys.flatten
|
219
|
-
.each_with_object(
|
219
|
+
.each_with_object({}) { |key, hsh| hsh[key] = self[key] if key?(key) }
|
220
220
|
end
|
221
221
|
|
222
222
|
def slice!(*keys)
|
@@ -270,7 +270,7 @@ module ActiveObject
|
|
270
270
|
|
271
271
|
# rubocop:disable Lint/UnusedMethodArgument
|
272
272
|
def transform_keys!(&block)
|
273
|
-
return
|
273
|
+
return enum_for(:transform_keys!) unless block_given?
|
274
274
|
|
275
275
|
each_key { |key| self[yield(key)] = delete(key) }
|
276
276
|
self
|
@@ -283,7 +283,7 @@ module ActiveObject
|
|
283
283
|
|
284
284
|
# rubocop:disable Lint/UnusedMethodArgument
|
285
285
|
def transform_values!(&block)
|
286
|
-
return
|
286
|
+
return enum_for(:transform_values!) unless block_given?
|
287
287
|
|
288
288
|
each { |key, val| self[key] = yield(val) }
|
289
289
|
end
|
@@ -3,7 +3,18 @@
|
|
3
3
|
module ActiveObject
|
4
4
|
module Integer
|
5
5
|
ROMAN_VALUES ||= {
|
6
|
-
M: 1000,
|
6
|
+
M: 1000,
|
7
|
+
CM: 900,
|
8
|
+
D: 500,
|
9
|
+
CD: 400,
|
10
|
+
C: 100,
|
11
|
+
XC: 90,
|
12
|
+
L: 50,
|
13
|
+
XL: 40,
|
14
|
+
X: 10,
|
15
|
+
IX: 9,
|
16
|
+
V: 5,
|
17
|
+
IV: 4,
|
7
18
|
I: 1
|
8
19
|
}.freeze
|
9
20
|
|
data/lib/active_object/kernel.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
if ActiveObject.configuration.autoload_kernel
|
4
4
|
module Kernel
|
5
5
|
|
6
|
-
SANITIZE_EVAL_REGEX ||= /\[\d*,?\d*,?\d*\]
|
6
|
+
SANITIZE_EVAL_REGEX ||= /\[\d*,?\d*,?\d*\]/.freeze
|
7
|
+
CALLER_METHOD_REGEX ||= /`([^']*)'/.freeze
|
7
8
|
|
8
|
-
# rubocop:disable
|
9
|
+
# rubocop:disable Security/Eval
|
9
10
|
def safe_eval
|
10
11
|
eval(self)
|
11
12
|
rescue Exception
|
@@ -18,13 +19,13 @@ if ActiveObject.configuration.autoload_kernel
|
|
18
19
|
|
19
20
|
eval(val)
|
20
21
|
end
|
21
|
-
# rubocop:enable
|
22
|
+
# rubocop:enable Security/Eval
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
26
|
# rubocop:disable Style/PerlBackrefs
|
26
27
|
def caller_name
|
27
|
-
caller(1..1).first =~
|
28
|
+
caller(1..1).first =~ CALLER_METHOD_REGEX && $1
|
28
29
|
end
|
29
30
|
# rubocop:enable Style/PerlBackrefs
|
30
31
|
|
@@ -40,16 +40,22 @@ module ActiveObject
|
|
40
40
|
meter meters millimeter millimeters centimeter centimeters decimeter decimeters decameter
|
41
41
|
decameters hectometer hectometers kilometer kilometers
|
42
42
|
],
|
43
|
-
imperical: %i[
|
43
|
+
imperical: %i[
|
44
|
+
inch inches foot feet yard yards mile miles nautical_mile nautical_miles
|
45
|
+
]
|
44
46
|
}.freeze
|
45
47
|
MASS_KEYS ||= {
|
46
48
|
metric: %i[
|
47
49
|
gram grams milligram milligrams centigram centigrams decigram decigrams decagram decagrams
|
48
50
|
hectogram hectograms kilogram kilograms metric_ton metric_tons
|
49
51
|
],
|
50
|
-
imperical: %i[
|
52
|
+
imperical: %i[
|
53
|
+
ounce ounces pound pounds stone stones ton tons
|
54
|
+
]
|
51
55
|
}.freeze
|
52
|
-
TEMPERATURE_KEYS ||= %i[
|
56
|
+
TEMPERATURE_KEYS ||= %i[
|
57
|
+
celsius fahrenheit kelvin
|
58
|
+
].freeze
|
53
59
|
TIME_KEYS ||= %i[
|
54
60
|
second seconds minute minutes hour hours day days week weeks year years decade decades century
|
55
61
|
centuries millennium millenniums
|
@@ -323,15 +329,13 @@ module ActiveObject
|
|
323
329
|
# rubocop:enable Style/NumericPredicate, Style/YodaCondition
|
324
330
|
|
325
331
|
def ordinal
|
326
|
-
if (11..13).cover?(abs % 100)
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
else 'th'
|
334
|
-
end
|
332
|
+
return 'th' if (11..13).cover?(abs % 100)
|
333
|
+
|
334
|
+
case abs % 10
|
335
|
+
when 1 then 'st'
|
336
|
+
when 2 then 'nd'
|
337
|
+
when 3 then 'rd'
|
338
|
+
else 'th'
|
335
339
|
end
|
336
340
|
end
|
337
341
|
|
@@ -356,8 +360,7 @@ module ActiveObject
|
|
356
360
|
to_s.rjust(precision, pad_number.to_s)
|
357
361
|
end
|
358
362
|
|
359
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
360
|
-
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
|
363
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength, Metrics/PerceivedComplexity
|
361
364
|
def pad_precision(options = {})
|
362
365
|
pad_number = options[:pad_number] || 0
|
363
366
|
precision = options[:precision] || 2
|
@@ -374,8 +377,7 @@ module ActiveObject
|
|
374
377
|
string[0..(ljust_count - 1)]
|
375
378
|
end
|
376
379
|
end
|
377
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
378
|
-
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
380
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength, Metrics/PerceivedComplexity
|
379
381
|
|
380
382
|
def percentage_of(number)
|
381
383
|
return 0 if zero? || number.zero?
|
@@ -433,6 +435,7 @@ module ActiveObject
|
|
433
435
|
|
434
436
|
def to_byte(from, to)
|
435
437
|
assert_inclusion_of_valid_keys!(BYTE_KEYS, from, to)
|
438
|
+
|
436
439
|
to_f * 1.send("#{from}_in_bytes").to_f / 1.send("#{to}_in_bytes").to_f
|
437
440
|
end
|
438
441
|
|
@@ -445,6 +448,7 @@ module ActiveObject
|
|
445
448
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
446
449
|
def to_length(from, to)
|
447
450
|
assert_inclusion_of_valid_keys!(LENGTH_KEYS.values.flatten, from, to)
|
451
|
+
|
448
452
|
metric_keys = LENGTH_KEYS.fetch(:metric)
|
449
453
|
return self if from == to
|
450
454
|
|
@@ -467,11 +471,10 @@ module ActiveObject
|
|
467
471
|
end
|
468
472
|
end
|
469
473
|
end
|
470
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
471
474
|
|
472
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
473
475
|
def to_mass(from, to)
|
474
476
|
assert_inclusion_of_valid_keys!(MASS_KEYS.values.flatten, from, to)
|
477
|
+
|
475
478
|
metric_keys = MASS_KEYS.fetch(:metric)
|
476
479
|
return self if from == to
|
477
480
|
|
@@ -503,10 +506,10 @@ module ActiveObject
|
|
503
506
|
difference = (self - value).abs
|
504
507
|
|
505
508
|
values.each do |val|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
509
|
+
next unless (self - val).abs < difference
|
510
|
+
|
511
|
+
difference = (self - val).abs
|
512
|
+
value = val
|
510
513
|
end
|
511
514
|
|
512
515
|
value
|
@@ -518,12 +521,13 @@ module ActiveObject
|
|
518
521
|
"#{pad_precision(options.only(:precision))}#{unit}"
|
519
522
|
end
|
520
523
|
|
521
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
524
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
522
525
|
def to_temperature(from, to)
|
523
526
|
assert_inclusion_of_valid_keys!(TEMPERATURE_KEYS, from, to)
|
524
|
-
return self if from == to
|
525
527
|
|
526
528
|
case to
|
529
|
+
when from
|
530
|
+
self
|
527
531
|
when :celsius
|
528
532
|
from == :kelvin ? (self - 273.15) : ((self - 32.0) * 5.0 / 9.0)
|
529
533
|
when :fahrenheit
|
@@ -532,10 +536,11 @@ module ActiveObject
|
|
532
536
|
from == :celsius ? (self + 273.15) : (((self - 32.0) * 5.0 / 9.0) + 273.15)
|
533
537
|
end
|
534
538
|
end
|
535
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
539
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
536
540
|
|
537
541
|
def to_time(from, to)
|
538
542
|
assert_inclusion_of_valid_keys!(TIME_KEYS, from, to)
|
543
|
+
|
539
544
|
(to_f * 1.send("#{from}_in_seconds").to_f) / 1.send("#{to}_in_seconds").to_f
|
540
545
|
end
|
541
546
|
|
data/lib/active_object/object.rb
CHANGED
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
module ActiveObject
|
4
4
|
module Object
|
5
|
-
FALSE_VALUES ||= [
|
6
|
-
|
5
|
+
FALSE_VALUES ||= [
|
6
|
+
false, 0, '0', 'false', 'FALSE', 'f', 'F'
|
7
|
+
].freeze
|
8
|
+
TRUE_VALUES ||= [
|
9
|
+
true, 1, '1', 'true', 'TRUE', 't', 'T'
|
10
|
+
].freeze
|
7
11
|
|
8
12
|
def array?
|
9
13
|
is_a?(Array)
|
data/lib/active_object/range.rb
CHANGED
@@ -8,12 +8,10 @@ module ActiveObject
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def include_with_range?(other)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
include?(other)
|
16
|
-
end
|
11
|
+
return include?(other) unless other.is_a?(Range)
|
12
|
+
|
13
|
+
operator = exclude_end? && !other.exclude_end? ? :< : :<=
|
14
|
+
include?(other.first) && other.last.send(operator, last)
|
17
15
|
end
|
18
16
|
|
19
17
|
def overlaps?(other)
|
data/lib/active_object/string.rb
CHANGED
@@ -5,10 +5,12 @@ module ActiveObject
|
|
5
5
|
|
6
6
|
def any?(*keys)
|
7
7
|
included = false
|
8
|
+
|
8
9
|
keys.flatten.each do |key|
|
9
10
|
included = include?(key)
|
10
11
|
break if included
|
11
12
|
end
|
13
|
+
|
12
14
|
included
|
13
15
|
end
|
14
16
|
|
@@ -19,7 +21,6 @@ module ActiveObject
|
|
19
21
|
def camelize(first_letter = :upper)
|
20
22
|
if first_letter.to_sym != :lower
|
21
23
|
regex_last = ::Regexp.last_match(1).upcase
|
22
|
-
|
23
24
|
to_s.gsub(%r{\/(.?)}) { "::#{regex_last}" }.gsub(%r{^/(?:^|_)(.)}) { regex_last }
|
24
25
|
else
|
25
26
|
"#{to_s.first.chr.downcase}#{camelize(self)[1..-1]}"
|
@@ -265,8 +266,7 @@ module ActiveObject
|
|
265
266
|
when String then chars_to_keep.chars
|
266
267
|
when Array then chars_to_keep.map(&:to_s)
|
267
268
|
when Range then chars_to_keep.to_a.map(&:to_s)
|
268
|
-
else
|
269
|
-
raise TypeError, 'Invalid parameter'
|
269
|
+
else raise TypeError, 'Invalid parameter'
|
270
270
|
end
|
271
271
|
|
272
272
|
chars.keep_if { |chr| chars_to_keep.include?(chr) }.join
|
@@ -323,10 +323,10 @@ module ActiveObject
|
|
323
323
|
def truncate(truncate_at, options = {})
|
324
324
|
return dup unless length > truncate_at
|
325
325
|
|
326
|
+
seperator = options[:separator]
|
326
327
|
omission = options[:omission] || '...'
|
327
328
|
size_with_room_for_omission = truncate_at - omission.length
|
328
329
|
|
329
|
-
seperator = options[:separator]
|
330
330
|
stop = if seperator
|
331
331
|
rindex(seperator || '', size_with_room_for_omission) || size_with_room_for_omission
|
332
332
|
else
|
@@ -339,7 +339,6 @@ module ActiveObject
|
|
339
339
|
def truncate_words(words_count, options = {})
|
340
340
|
sep = options[:separator] || /\s+/
|
341
341
|
sep = ::Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
|
342
|
-
|
343
342
|
return self unless self =~ /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m
|
344
343
|
|
345
344
|
"#{::Regexp.last_match(1)}#{options[:omissio] || '...'}"
|
data/lib/active_object/time.rb
CHANGED
@@ -201,6 +201,7 @@ module ActiveObject
|
|
201
201
|
|
202
202
|
def count_seconds_since(time)
|
203
203
|
time = time.to_time if time.respond_to?(:to_time)
|
204
|
+
|
204
205
|
(to_f - time.to_f).abs
|
205
206
|
end
|
206
207
|
|
@@ -221,7 +222,6 @@ module ActiveObject
|
|
221
222
|
def format(string)
|
222
223
|
delimiters = string.scan(/\W+/)
|
223
224
|
formatters = string.scan(/[a-z0-9_]+/i)
|
224
|
-
|
225
225
|
string = formatters.map { |unit| "%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift}" }
|
226
226
|
|
227
227
|
strftime(string.join)
|
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: 5.
|
4
|
+
version: 5.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|