active_object 4.0.4 → 4.0.5
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/.reek +3 -2
- data/README.md +4 -3
- data/lib/active_object/array.rb +6 -10
- data/lib/active_object/enumerable.rb +11 -20
- data/lib/active_object/hash.rb +20 -19
- data/lib/active_object/integer.rb +5 -4
- data/lib/active_object/numeric.rb +16 -15
- data/lib/active_object/string.rb +38 -50
- 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: f37d9b60515ee24fd151c29380721c78d9847e7a
|
4
|
+
data.tar.gz: 4221325bf0f0a5bc213dae699cd996b4a740a443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddfb290bd737a3644aa0bd4e955217b82f3e8f6dfb9823c6749e48b4fb1fcfba38278bba86aaaa04654abc6d0aec6921324188b39bae4f493942c0fceb2f56ba
|
7
|
+
data.tar.gz: 8d741cf05d954ed934158ac1bade24688d1f4a5cd8083ea6df25e85993dbf09d1407775f5bb9fae0ce756c9090f038423eb77fa19ba7c13feefbcf4656e1dbb4
|
data/.reek
CHANGED
data/README.md
CHANGED
@@ -450,10 +450,11 @@ end
|
|
450
450
|
## Hash
|
451
451
|
|
452
452
|
####Assert Valid Keys:####
|
453
|
-
`assert_valid_keys` raises an error if key is not included in a list of keys.
|
453
|
+
`assert_valid_keys` and `assert_valid_keys!` raises an error if key is not included in a list of keys.
|
454
454
|
|
455
455
|
```ruby
|
456
456
|
{}.assert_valid_keys(:foo) #=> {}
|
457
|
+
{}.assert_valid_keys!(:foo) #=> raises 'ArgumentError: Empty hash. Valid keys are: :foo'
|
457
458
|
{ foo: 'bar' }.assert_valid_keys(:foo) #=> { foo: 'bar' }
|
458
459
|
{ foo: 'bar', baz: 'boz' }.assert_valid_keys(:foo, :boo) #=> raises 'ArgumentError: Unknown key: :baz. Valid keys are: :foo, :boo'
|
459
460
|
```
|
@@ -1654,8 +1655,8 @@ false.truthy? #=> false
|
|
1654
1655
|
`parameterize` and `parameterize!` makes string suitable for a dashed url parameter string.
|
1655
1656
|
|
1656
1657
|
```ruby
|
1657
|
-
'example_string'.parameterize
|
1658
|
-
'example_string'.parameterize('?') #=> 'example?string'
|
1658
|
+
'example_string'.parameterize #=> 'example-string'
|
1659
|
+
'example_string'.parameterize(separator: '?') #=> 'example?string'
|
1659
1660
|
```
|
1660
1661
|
|
1661
1662
|
####Pollute:####
|
data/lib/active_object/array.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module ActiveObject::Array
|
2
2
|
|
3
3
|
def after(value)
|
4
|
-
return
|
4
|
+
return unless include?(value)
|
5
5
|
|
6
6
|
self[(index(value).to_i + 1) % length]
|
7
7
|
end
|
8
8
|
|
9
9
|
def before(value)
|
10
|
-
return
|
10
|
+
return unless include?(value)
|
11
11
|
|
12
12
|
self[(index(value).to_i - 1) % length]
|
13
13
|
end
|
@@ -36,18 +36,14 @@ module ActiveObject::Array
|
|
36
36
|
|
37
37
|
def dig(key, *rest)
|
38
38
|
value = (self[key] rescue nil)
|
39
|
-
return if value.nil?
|
40
39
|
|
41
|
-
if
|
42
|
-
|
43
|
-
|
44
|
-
value.dig(*rest)
|
45
|
-
end
|
40
|
+
return if value.nil?
|
41
|
+
return value if rest.empty?
|
42
|
+
return value.dig(*rest) if value.respond_to?(:dig)
|
46
43
|
end
|
47
44
|
|
48
45
|
def duplicates(minimum = 2)
|
49
46
|
hash = Hash.new(0)
|
50
|
-
|
51
47
|
each { |val| hash[val] += 1 }
|
52
48
|
hash.delete_if { |_, val| val < minimum }.keys
|
53
49
|
end
|
@@ -57,7 +53,7 @@ module ActiveObject::Array
|
|
57
53
|
end
|
58
54
|
|
59
55
|
def groups(number)
|
60
|
-
return
|
56
|
+
return [] if number <= 0
|
61
57
|
|
62
58
|
num, rem = length.divmod(number)
|
63
59
|
collection = (0..(num - 1)).collect { |val| self[(val * number), number] }
|
@@ -5,12 +5,7 @@ module Enumerable
|
|
5
5
|
result = []
|
6
6
|
each do |ele|
|
7
7
|
last_res = result.last
|
8
|
-
|
9
|
-
if last_res && (yield(last_res.last) == yield(ele))
|
10
|
-
last_res << ele
|
11
|
-
else
|
12
|
-
result << [ele]
|
13
|
-
end
|
8
|
+
last_res && (yield(last_res.last) == yield(ele)) ? last_res << ele : result << [ele]
|
14
9
|
end
|
15
10
|
result
|
16
11
|
end
|
@@ -34,9 +29,7 @@ module Enumerable
|
|
34
29
|
|
35
30
|
def drop_last(num)
|
36
31
|
collection_length = to_a.length
|
37
|
-
|
38
|
-
return(self) if num > collection_length
|
39
|
-
|
32
|
+
return self if num > collection_length
|
40
33
|
self[0...(collection_length - num)]
|
41
34
|
end
|
42
35
|
|
@@ -108,7 +101,7 @@ module Enumerable
|
|
108
101
|
end
|
109
102
|
|
110
103
|
def mean(identity = 0)
|
111
|
-
return
|
104
|
+
return identity unless length.positive?
|
112
105
|
|
113
106
|
collection_length = length
|
114
107
|
sum.to_f / collection_length.to_f
|
@@ -121,6 +114,7 @@ module Enumerable
|
|
121
114
|
collection_sorted = sort
|
122
115
|
|
123
116
|
return(identity) unless collection_length > 0.0
|
117
|
+
|
124
118
|
half_collection = collection_length / 2.0
|
125
119
|
sorted_collection = collection_sorted[half_collection]
|
126
120
|
|
@@ -133,17 +127,14 @@ module Enumerable
|
|
133
127
|
|
134
128
|
# rubocop:disable Metrics/AbcSize
|
135
129
|
def mode(identity = 0)
|
136
|
-
return
|
130
|
+
return identity unless length.positive?
|
137
131
|
|
138
132
|
frequency_distribution = each_with_object(Hash.new(0)) { |val, hsh| hsh[val] += 1 }
|
139
133
|
frequency_top_two = frequency_distribution.sort_by { |_, val| -val }.take(2)
|
140
134
|
top_two_first = frequency_top_two.first
|
141
135
|
|
142
|
-
if frequency_top_two.length != 1 && top_two_first.last == frequency_top_two.last.last
|
143
|
-
|
144
|
-
else
|
145
|
-
top_two_first.first
|
146
|
-
end
|
136
|
+
return if frequency_top_two.length != 1 && top_two_first.last == frequency_top_two.last.last
|
137
|
+
top_two_first.first
|
147
138
|
end
|
148
139
|
# rubocop:ensable Metrics/AbcSize
|
149
140
|
|
@@ -156,7 +147,7 @@ module Enumerable
|
|
156
147
|
end
|
157
148
|
|
158
149
|
def range(identity = 0)
|
159
|
-
return
|
150
|
+
return identity unless length.positive?
|
160
151
|
|
161
152
|
collection_sorted = sort
|
162
153
|
collection_sorted.last - collection_sorted.first
|
@@ -173,7 +164,7 @@ module Enumerable
|
|
173
164
|
end
|
174
165
|
|
175
166
|
def standard_deviation(identity = 0)
|
176
|
-
return
|
167
|
+
return identity if length < 2
|
177
168
|
|
178
169
|
Math.sqrt(variance)
|
179
170
|
end
|
@@ -189,7 +180,7 @@ module Enumerable
|
|
189
180
|
def take_last(num)
|
190
181
|
collection_length = to_a.length
|
191
182
|
|
192
|
-
return
|
183
|
+
return self if num > collection_length
|
193
184
|
|
194
185
|
self[(collection_length - num)..-1]
|
195
186
|
end
|
@@ -205,7 +196,7 @@ module Enumerable
|
|
205
196
|
def variance(identity = 0)
|
206
197
|
collection_length = length
|
207
198
|
|
208
|
-
return
|
199
|
+
return identity if collection_length <= 1
|
209
200
|
|
210
201
|
total = inject(0.0) { |sum, val| sum + (val - mean)**2.0 }
|
211
202
|
total.to_f / (collection_length.to_f - 1.0)
|
data/lib/active_object/hash.rb
CHANGED
@@ -4,10 +4,19 @@ module ActiveObject::Hash
|
|
4
4
|
valid_keys.flatten!
|
5
5
|
|
6
6
|
each_key do |key|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
next if valid_keys.include?(key)
|
8
|
+
|
9
|
+
raise ArgumentError,
|
10
|
+
"Unknown key: #{key.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_valid_keys!(*valid_keys)
|
15
|
+
if empty?
|
16
|
+
raise ArgumentError,
|
17
|
+
"Empty hash. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}"
|
18
|
+
else
|
19
|
+
assert_valid_keys(*valid_keys)
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
@@ -43,13 +52,10 @@ module ActiveObject::Hash
|
|
43
52
|
|
44
53
|
def dig(key, *rest)
|
45
54
|
value = (self[key] rescue nil)
|
46
|
-
return if value.nil?
|
47
55
|
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
value.dig(*rest)
|
52
|
-
end
|
56
|
+
return if value.nil?
|
57
|
+
return value if rest.empty?
|
58
|
+
return value.dig(*rest) if value.respond_to?(:dig)
|
53
59
|
end
|
54
60
|
|
55
61
|
def except(*keys)
|
@@ -148,9 +154,8 @@ module ActiveObject::Hash
|
|
148
154
|
end
|
149
155
|
|
150
156
|
def slice(*keys)
|
151
|
-
keys
|
152
|
-
|
153
|
-
.each_with_object(self.class.new) { |key, hsh| hsh[key] = self[key] if key?(key) }
|
157
|
+
keys.flatten
|
158
|
+
.each_with_object(self.class.new) { |key, hsh| hsh[key] = self[key] if key?(key) }
|
154
159
|
end
|
155
160
|
|
156
161
|
def slice!(*keys)
|
@@ -169,9 +174,7 @@ module ActiveObject::Hash
|
|
169
174
|
end
|
170
175
|
|
171
176
|
def stringify_keys!
|
172
|
-
each_with_object({})
|
173
|
-
options[key.to_s] = val
|
174
|
-
end
|
177
|
+
each_with_object({}) { |(key, val), options| options[key.to_s] = val }
|
175
178
|
end
|
176
179
|
|
177
180
|
def strip
|
@@ -187,9 +190,7 @@ module ActiveObject::Hash
|
|
187
190
|
end
|
188
191
|
|
189
192
|
def symbolize_keys!
|
190
|
-
each_with_object({})
|
191
|
-
options[(key.to_sym rescue key) || key] = val
|
192
|
-
end
|
193
|
+
each_with_object({}) { |(key, val), options| options[(key.to_sym rescue key) || key] = val }
|
193
194
|
end
|
194
195
|
|
195
196
|
def symbolize_and_underscore_keys
|
@@ -5,8 +5,9 @@ module ActiveObject::Integer
|
|
5
5
|
}.freeze
|
6
6
|
|
7
7
|
def factorial
|
8
|
-
return
|
9
|
-
|
8
|
+
return 1 if zero?
|
9
|
+
|
10
|
+
2.upto(self).inject(1) { |acc, elem| acc * elem }
|
10
11
|
end
|
11
12
|
|
12
13
|
def of(&block)
|
@@ -14,8 +15,8 @@ module ActiveObject::Integer
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def roman
|
17
|
-
return
|
18
|
-
return
|
18
|
+
return '' if zero?
|
19
|
+
return "-#{(-self).roman}" if negative?
|
19
20
|
|
20
21
|
ROMAN_VALUES.each { |key, val| return("#{key}#{(self - val).roman}") if val <= self }
|
21
22
|
end
|
@@ -89,10 +89,12 @@ module ActiveObject::Numeric
|
|
89
89
|
min_min = minimum.min
|
90
90
|
min_max = minimum.max
|
91
91
|
|
92
|
-
return
|
92
|
+
return min_min if self < min_min
|
93
|
+
|
93
94
|
self > min_max ? min_max : self
|
94
95
|
else
|
95
|
-
return
|
96
|
+
return minimum if self < minimum
|
97
|
+
|
96
98
|
self > maximum ? maximum : self
|
97
99
|
end
|
98
100
|
end
|
@@ -355,6 +357,7 @@ module ActiveObject::Numeric
|
|
355
357
|
string << separator unless string.include?(separator)
|
356
358
|
ljust_count = string.split(separator).first.length
|
357
359
|
ljust_count += (string.count(separator) + precision) if precision.positive?
|
360
|
+
|
358
361
|
if ljust_count >= string.length
|
359
362
|
string.ljust(ljust_count, pad_number.to_s)
|
360
363
|
else
|
@@ -413,8 +416,7 @@ module ActiveObject::Numeric
|
|
413
416
|
alias_method :terabyte_in_bytes, :terabytes_in_bytes
|
414
417
|
|
415
418
|
def to_byte(from, to)
|
416
|
-
|
417
|
-
|
419
|
+
assert_inclusion_of_valid_keys!(BYTE_KEYS, from, to)
|
418
420
|
to_f * 1.send("#{from}_in_bytes").to_f / 1.send("#{to}_in_bytes").to_f
|
419
421
|
end
|
420
422
|
|
@@ -426,9 +428,9 @@ module ActiveObject::Numeric
|
|
426
428
|
|
427
429
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
428
430
|
def to_length(from, to)
|
429
|
-
|
431
|
+
assert_inclusion_of_valid_keys!(LENGTH_KEYS.values.flatten, from, to)
|
430
432
|
metric_keys = LENGTH_KEYS.fetch(:metric)
|
431
|
-
return
|
433
|
+
return self if from == to
|
432
434
|
metrics_included_from = metric_keys.include?(from)
|
433
435
|
|
434
436
|
case to
|
@@ -451,9 +453,9 @@ module ActiveObject::Numeric
|
|
451
453
|
|
452
454
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
453
455
|
def to_mass(from, to)
|
454
|
-
|
456
|
+
assert_inclusion_of_valid_keys!(MASS_KEYS.values.flatten, from, to)
|
455
457
|
metric_keys = MASS_KEYS.fetch(:metric)
|
456
|
-
return
|
458
|
+
return self if from == to
|
457
459
|
metrics_included_from = metric_keys.include?(from)
|
458
460
|
|
459
461
|
case to
|
@@ -476,7 +478,7 @@ module ActiveObject::Numeric
|
|
476
478
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
477
479
|
|
478
480
|
def to_nearest_value(values = [])
|
479
|
-
return
|
481
|
+
return self if values.length.zero?
|
480
482
|
|
481
483
|
value = values.first
|
482
484
|
difference = (self - value).abs
|
@@ -499,8 +501,8 @@ module ActiveObject::Numeric
|
|
499
501
|
|
500
502
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
501
503
|
def to_temperature(from, to)
|
502
|
-
|
503
|
-
return
|
504
|
+
assert_inclusion_of_valid_keys!(TEMPERATURE_KEYS, from, to)
|
505
|
+
return self if from == to
|
504
506
|
|
505
507
|
case to
|
506
508
|
when :celsius
|
@@ -514,8 +516,7 @@ module ActiveObject::Numeric
|
|
514
516
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
515
517
|
|
516
518
|
def to_time(from, to)
|
517
|
-
|
518
|
-
|
519
|
+
assert_inclusion_of_valid_keys!(TIME_KEYS, from, to)
|
519
520
|
(to_f * 1.send("#{from}_in_seconds").to_f) / 1.send("#{to}_in_seconds").to_f
|
520
521
|
end
|
521
522
|
|
@@ -532,7 +533,7 @@ module ActiveObject::Numeric
|
|
532
533
|
alias_method :week_in_seconds, :weeks_in_seconds
|
533
534
|
|
534
535
|
def within?(number, epsilon = 0.01)
|
535
|
-
return
|
536
|
+
return self == number if epsilon.zero?
|
536
537
|
|
537
538
|
alpha = to_f
|
538
539
|
beta = number.to_f
|
@@ -554,7 +555,7 @@ module ActiveObject::Numeric
|
|
554
555
|
|
555
556
|
private
|
556
557
|
|
557
|
-
def
|
558
|
+
def assert_inclusion_of_valid_keys!(cns, from, to)
|
558
559
|
return if cns.include?(from) && cns.include?(to)
|
559
560
|
raise ArgumentError,
|
560
561
|
[
|
data/lib/active_object/string.rb
CHANGED
@@ -17,9 +17,7 @@ module ActiveObject::String
|
|
17
17
|
if first_letter.to_sym != :lower
|
18
18
|
regex_last = Regexp.last_match(1).upcase
|
19
19
|
|
20
|
-
to_s
|
21
|
-
.gsub(%r{\/(.?)}) { "::#{regex_last}" }
|
22
|
-
.gsub(%r{^/(?:^|_)(.)}) { regex_last }
|
20
|
+
to_s.gsub(%r{\/(.?)}) { "::#{regex_last}" }.gsub(%r{^/(?:^|_)(.)}) { regex_last }
|
23
21
|
else
|
24
22
|
"#{to_s.first.chr.downcase}#{camelize(self)[1..-1]}"
|
25
23
|
end
|
@@ -78,7 +76,7 @@ module ActiveObject::String
|
|
78
76
|
end
|
79
77
|
|
80
78
|
def ellipsize(ellipsize_at, options = {})
|
81
|
-
return
|
79
|
+
return self if length <= ellipsize_at
|
82
80
|
|
83
81
|
separator = options[:separator] || '...'
|
84
82
|
offset = options[:offset] || 4
|
@@ -91,7 +89,7 @@ module ActiveObject::String
|
|
91
89
|
end
|
92
90
|
|
93
91
|
def first(limit = 1)
|
94
|
-
return
|
92
|
+
return '' if limit.zero?
|
95
93
|
|
96
94
|
limit >= length ? self : to(limit - 1)
|
97
95
|
end
|
@@ -107,12 +105,11 @@ module ActiveObject::String
|
|
107
105
|
def humanize(options = {})
|
108
106
|
capitalize = options[:capitalize] || true
|
109
107
|
|
110
|
-
underscore
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
.gsub(/\A\w/) { |str| capitalize ? str.upcase : str }
|
108
|
+
underscore.gsub(/_id\z/, '')
|
109
|
+
.tr('_', ' ')
|
110
|
+
.squish
|
111
|
+
.gsub(/([a-z\d]*)/i, &:downcase)
|
112
|
+
.gsub(/\A\w/) { |str| capitalize ? str.upcase : str }
|
116
113
|
end
|
117
114
|
|
118
115
|
def humanize!(options = {})
|
@@ -147,12 +144,11 @@ module ActiveObject::String
|
|
147
144
|
def labelize(options = {})
|
148
145
|
capitalize = options[:capitalize] || true
|
149
146
|
|
150
|
-
underscore
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
.gsub(/ id\z/, ' ID')
|
147
|
+
underscore.tr('_', ' ')
|
148
|
+
.squish
|
149
|
+
.gsub(/([a-z\d]*)/i, &:downcase)
|
150
|
+
.gsub(/\A\w/) { |str| capitalize ? str.upcase : str }
|
151
|
+
.gsub(/ id\z/, ' ID')
|
156
152
|
end
|
157
153
|
|
158
154
|
alias_method :labelcase, :labelize
|
@@ -164,7 +160,7 @@ module ActiveObject::String
|
|
164
160
|
alias_method :labelcase!, :labelize!
|
165
161
|
|
166
162
|
def last(limit = 1)
|
167
|
-
return
|
163
|
+
return '' if limit.zero?
|
168
164
|
|
169
165
|
limit >= length ? self : from(-limit)
|
170
166
|
end
|
@@ -181,12 +177,12 @@ module ActiveObject::String
|
|
181
177
|
to_i.ordinalize
|
182
178
|
end
|
183
179
|
|
184
|
-
def parameterize(
|
185
|
-
underscore.gsub(/\s+/,
|
180
|
+
def parameterize(separator: '-')
|
181
|
+
underscore.gsub(/\s+/, separator).downcase
|
186
182
|
end
|
187
183
|
|
188
|
-
def parameterize!(
|
189
|
-
replace(parameterize(
|
184
|
+
def parameterize!(separator: '-')
|
185
|
+
replace(parameterize(separator: separator))
|
190
186
|
end
|
191
187
|
|
192
188
|
def pollute(delimiter = '^--^--^')
|
@@ -207,11 +203,7 @@ module ActiveObject::String
|
|
207
203
|
|
208
204
|
def remove(*patterns)
|
209
205
|
string = dup
|
210
|
-
|
211
|
-
patterns.flatten.each do |pat|
|
212
|
-
pat.is_a?(Range) ? string.slice!(pat) : string.gsub!(pat, '')
|
213
|
-
end
|
214
|
-
|
206
|
+
patterns.flatten.each { |pat| pat.is_a?(Range) ? string.slice!(pat) : string.gsub!(pat, '') }
|
215
207
|
string
|
216
208
|
end
|
217
209
|
|
@@ -236,13 +228,11 @@ module ActiveObject::String
|
|
236
228
|
end
|
237
229
|
|
238
230
|
def shift(*patterns)
|
239
|
-
if patterns.empty?
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
string
|
245
|
-
end
|
231
|
+
return self[0] if patterns.empty?
|
232
|
+
|
233
|
+
string = dup
|
234
|
+
patterns.flatten.each { |pat| string.sub!(pat, '') }
|
235
|
+
string
|
246
236
|
end
|
247
237
|
|
248
238
|
def shift!(*patterns)
|
@@ -274,11 +264,11 @@ module ActiveObject::String
|
|
274
264
|
end
|
275
265
|
|
276
266
|
def slugify
|
277
|
-
gsub(/[^\x00-\x7F]+/, '')
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
267
|
+
to_s.gsub(/[^\x00-\x7F]+/, '')
|
268
|
+
.gsub(/[^\w_ \-]+/i, '')
|
269
|
+
.gsub(/[ \-]+/i, '-')
|
270
|
+
.gsub(/^\-|\-$/i, '')
|
271
|
+
.downcase
|
282
272
|
end
|
283
273
|
|
284
274
|
def slugify!
|
@@ -318,7 +308,7 @@ module ActiveObject::String
|
|
318
308
|
end
|
319
309
|
|
320
310
|
def truncate(truncate_at, options = {})
|
321
|
-
return
|
311
|
+
return dup unless length > truncate_at
|
322
312
|
|
323
313
|
omission = options[:omission] || '...'
|
324
314
|
size_with_room_for_omission = truncate_at - omission.length
|
@@ -337,19 +327,17 @@ module ActiveObject::String
|
|
337
327
|
sep = options[:separator] || /\s+/
|
338
328
|
sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
|
339
329
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
self
|
344
|
-
end
|
330
|
+
return self unless self =~ /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m
|
331
|
+
|
332
|
+
"#{Regexp.last_match(1)}#{options[:omissio] || '...'}"
|
345
333
|
end
|
346
334
|
|
347
335
|
def underscore
|
348
|
-
gsub(/::/, '/')
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
336
|
+
to_s.gsub(/::/, '/')
|
337
|
+
.gsub(/([A-Z\d]+)([A-Z][a-z])/, "\1_\2")
|
338
|
+
.gsub(/([a-z\d])([A-Z])/, "\1_\2")
|
339
|
+
.tr('-', '_')
|
340
|
+
.downcase
|
353
341
|
end
|
354
342
|
|
355
343
|
def underscore!
|
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: 4.0.
|
4
|
+
version: 4.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.8
|
201
201
|
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: Gem for commonly used ruby object helpers.
|