lite-ruby 1.0.26 → 1.0.31

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a60b6620f1f96b3e70290ffef9a747511107a86449742e1be095be4aa0ffea91
4
- data.tar.gz: 23e7fdc0cf9e7948812d95b4f36528eb264d7e041f7986d86cf1ebff770d70a0
3
+ metadata.gz: 15a0127d8b5abef7b86a8b357d76bd81721b3e17633e25935d074c914f2ce6c9
4
+ data.tar.gz: 0e0cbbb3cb414574370770851e3423b1f09094d1aebd0a133897c24ad9b40588
5
5
  SHA512:
6
- metadata.gz: 883d36b8714d876f6a5f31da52da55c1da86641033724c94e2e0045e261e6e2427a4f1cb3f2d9bda234d564018f97f4c21efa55e8d9276826cead809d6c7f949
7
- data.tar.gz: a457a5207c0e203689ad0064232032b7419e13c9297e1ad7365ea8f5c0f699736eb5b9851a94c475262b21ab8429ae2772240e8d8f7046b6113ba53b61889d2c
6
+ metadata.gz: 28cb3f81b2df9ff0483153c8c7077c04220efa0012958d6533cd8903a6d7b22e1099ab77c5c3db6b024cf04d211c37eb8bae9581e6457c02ddf1d891a5bf7142
7
+ data.tar.gz: 5adfc54f1824eab97ab7f23f20ea4b33f3405fddbd97ba32d48fa93f883eb35e0f6f9d70ac24f39ff046ae5a0775a080e0fcffaea1cfd4ce3e353e50afcd1bf8
@@ -2,9 +2,12 @@ require:
2
2
  - rubocop-performance
3
3
  - rubocop-rspec
4
4
  AllCops:
5
- TargetRubyVersion: 2.6
5
+ TargetRubyVersion: 2.7
6
+ NewCops: enable
6
7
  DisplayCopNames: true
7
8
  DisplayStyleGuide: true
9
+ Gemspec/RequiredRubyVersion:
10
+ Enabled: false
8
11
  Layout/EmptyLinesAroundBlockBody:
9
12
  Exclude:
10
13
  - 'spec/**/**/*'
@@ -20,6 +23,8 @@ Layout/SpaceAroundMethodCallOperator:
20
23
  Enabled: true
21
24
  Lint/DeprecatedOpenSSLConstant:
22
25
  Enabled: true
26
+ Lint/MixedRegexpCaptureTypes:
27
+ Enabled: true
23
28
  Lint/RaiseException:
24
29
  Enabled: true
25
30
  Lint/StructNewOverride:
@@ -53,5 +58,11 @@ Style/HashTransformValues:
53
58
  Enabled: false
54
59
  Style/PerlBackrefs:
55
60
  Enabled: false
61
+ Style/RedundantRegexpCharacterClass:
62
+ Enabled: true
63
+ Style/RedundantRegexpEscape:
64
+ Enabled: true
65
+ Style/RedundantFetchBlock:
66
+ Enabled: true
56
67
  Style/SlicingWithRange:
57
68
  Enabled: false
@@ -4,6 +4,7 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.5
6
6
  - 2.6
7
+ - 2.7
7
8
  - ruby-head
8
9
  matrix:
9
10
  fast_finish: true
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.31] - 2020-09-21
10
+ ### Changed
11
+ - Changed `block_given?` => `defined?(yield)` for more performance
12
+
13
+ ## [1.0.30] - 2020-07-03
14
+ ### Added
15
+ - Added more Ruby 2.7 support
16
+
17
+ ## [1.0.29] - 2020-07-03
18
+ ### Added
19
+ - Added Ruby 2.7 support
20
+
21
+ ## [1.0.28] - 2020-06-25
22
+ # Changed
23
+ - Rename String => `encode_only` to `safe_encode`
24
+ # Removed
25
+ - Remove String => `ascii_only`
26
+
27
+ ## [1.0.26] - 2020-06-12
28
+ ### Added
29
+ - Added array => `all_after`
30
+ - Added array => `all_before`
31
+
9
32
  ## [1.0.26] - 2020-05-22
10
33
  ### Changed
11
34
  - Changed hash `to_open_struct` and `to_object` to be independent methods
@@ -1,36 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.26)
4
+ lite-ruby (1.0.31)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.0.3.1)
10
- actionview (= 6.0.3.1)
11
- activesupport (= 6.0.3.1)
9
+ actionpack (6.0.3.3)
10
+ actionview (= 6.0.3.3)
11
+ activesupport (= 6.0.3.3)
12
12
  rack (~> 2.0, >= 2.0.8)
13
13
  rack-test (>= 0.6.3)
14
14
  rails-dom-testing (~> 2.0)
15
15
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
- actionview (6.0.3.1)
17
- activesupport (= 6.0.3.1)
16
+ actionview (6.0.3.3)
17
+ activesupport (= 6.0.3.3)
18
18
  builder (~> 3.1)
19
19
  erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activesupport (6.0.3.1)
22
+ activesupport (6.0.3.3)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 0.7, < 2)
25
25
  minitest (~> 5.1)
26
26
  tzinfo (~> 1.1)
27
27
  zeitwerk (~> 2.2, >= 2.2.2)
28
- ast (2.4.0)
28
+ ast (2.4.1)
29
29
  builder (3.2.4)
30
30
  colorize (0.8.1)
31
- concurrent-ruby (1.1.6)
31
+ concurrent-ruby (1.1.7)
32
32
  crass (1.0.6)
33
- diff-lcs (1.3)
33
+ diff-lcs (1.4.4)
34
34
  erubi (1.9.0)
35
35
  fasterer (0.8.3)
36
36
  colorize (~> 0.7)
@@ -38,20 +38,20 @@ GEM
38
38
  generator_spec (0.9.4)
39
39
  activesupport (>= 3.0.0)
40
40
  railties (>= 3.0.0)
41
- i18n (1.8.2)
41
+ i18n (1.8.5)
42
42
  concurrent-ruby (~> 1.0)
43
- loofah (2.5.0)
43
+ loofah (2.7.0)
44
44
  crass (~> 1.0.2)
45
45
  nokogiri (>= 1.5.9)
46
46
  method_source (1.0.0)
47
47
  mini_portile2 (2.4.0)
48
- minitest (5.14.1)
49
- nokogiri (1.10.9)
48
+ minitest (5.14.2)
49
+ nokogiri (1.10.10)
50
50
  mini_portile2 (~> 2.4.0)
51
- parallel (1.19.1)
52
- parser (2.7.1.2)
53
- ast (~> 2.4.0)
54
- rack (2.2.2)
51
+ parallel (1.19.2)
52
+ parser (2.7.1.4)
53
+ ast (~> 2.4.1)
54
+ rack (2.2.3)
55
55
  rack-test (1.1.0)
56
56
  rack (>= 1.0, < 3)
57
57
  rails-dom-testing (2.0.3)
@@ -59,14 +59,15 @@ GEM
59
59
  nokogiri (>= 1.6)
60
60
  rails-html-sanitizer (1.3.0)
61
61
  loofah (~> 2.3)
62
- railties (6.0.3.1)
63
- actionpack (= 6.0.3.1)
64
- activesupport (= 6.0.3.1)
62
+ railties (6.0.3.3)
63
+ actionpack (= 6.0.3.3)
64
+ activesupport (= 6.0.3.3)
65
65
  method_source
66
66
  rake (>= 0.8.7)
67
67
  thor (>= 0.20.3, < 2.0)
68
68
  rainbow (3.0.0)
69
69
  rake (13.0.1)
70
+ regexp_parser (1.8.0)
70
71
  rexml (3.2.4)
71
72
  rspec (3.9.0)
72
73
  rspec-core (~> 3.9.0)
@@ -81,30 +82,32 @@ GEM
81
82
  diff-lcs (>= 1.2.0, < 2.0)
82
83
  rspec-support (~> 3.9.0)
83
84
  rspec-support (3.9.3)
84
- rubocop (0.84.0)
85
+ rubocop (0.91.0)
85
86
  parallel (~> 1.10)
86
- parser (>= 2.7.0.1)
87
+ parser (>= 2.7.1.1)
87
88
  rainbow (>= 2.2.2, < 4.0)
89
+ regexp_parser (>= 1.7)
88
90
  rexml
89
- rubocop-ast (>= 0.0.3)
91
+ rubocop-ast (>= 0.4.0, < 1.0)
90
92
  ruby-progressbar (~> 1.7)
91
93
  unicode-display_width (>= 1.4.0, < 2.0)
92
- rubocop-ast (0.0.3)
93
- parser (>= 2.7.0.1)
94
- rubocop-performance (1.6.0)
95
- rubocop (>= 0.71.0)
96
- rubocop-rspec (1.39.0)
97
- rubocop (>= 0.68.1)
94
+ rubocop-ast (0.4.2)
95
+ parser (>= 2.7.1.4)
96
+ rubocop-performance (1.8.1)
97
+ rubocop (>= 0.87.0)
98
+ rubocop-ast (>= 0.4.0)
99
+ rubocop-rspec (1.43.2)
100
+ rubocop (~> 0.87)
98
101
  ruby-progressbar (1.10.1)
99
- ruby_parser (3.14.2)
102
+ ruby_parser (3.15.0)
100
103
  sexp_processor (~> 4.9)
101
- sexp_processor (4.14.1)
104
+ sexp_processor (4.15.1)
102
105
  thor (1.0.1)
103
106
  thread_safe (0.3.6)
104
107
  tzinfo (1.2.7)
105
108
  thread_safe (~> 0.1)
106
109
  unicode-display_width (1.7.0)
107
- zeitwerk (2.3.0)
110
+ zeitwerk (2.4.0)
108
111
 
109
112
  PLATFORMS
110
113
  ruby
@@ -64,14 +64,24 @@ Returns the value after a given value.
64
64
  ['1', '2', '3'].after('4') #=> nil
65
65
  ```
66
66
 
67
- `bury`
67
+ `all_after`
68
68
  ------
69
- Updates a deeply nested value.
69
+ Returns all values after a given value.
70
70
 
71
71
  ```ruby
72
- ['1', ['2']].bury(1, '3') #=> ['1', '3']
73
- ['1', ['2']].bury(1, 0, '3') #=> ['1', ['3']]
74
- ['1', ['2']].bury(1) #=> raises ArgumentError: '2 or more arguments required'
72
+ ['1', '2', '3'].all_after('1') #=> [2, 3]
73
+ ['1', '2', '3'].all_after('3') #=> nil
74
+ ['1', '2', '3'].all_after('4') #=> nil
75
+ ```
76
+
77
+ `all_before`
78
+ ------
79
+ Returns all values before a given value.
80
+
81
+ ```ruby
82
+ ['1', '2', '3'].all_before('3') #=> [1, 2]
83
+ ['1', '2', '3'].all_before('1') #=> nil
84
+ ['1', '2', '3'].all_before('4') #=> nil
75
85
  ```
76
86
 
77
87
  `before`
@@ -84,6 +94,16 @@ Returns the value before a given value.
84
94
  ['1', '2', '3'].before('4') #=> nil
85
95
  ```
86
96
 
97
+ `bury`
98
+ ------
99
+ Updates a deeply nested value.
100
+
101
+ ```ruby
102
+ ['1', ['2']].bury(1, '3') #=> ['1', '3']
103
+ ['1', ['2']].bury(1, 0, '3') #=> ['1', ['3']]
104
+ ['1', ['2']].bury(1) #=> raises ArgumentError: '2 or more arguments required'
105
+ ```
106
+
87
107
  `delete_first(!)`
88
108
  ------
89
109
  Removes the first element from an array. Like `shift`, but returns the array instead of the removed element.
@@ -323,8 +323,8 @@ Moves a key value pair to the head of the hash.
323
323
  Rename the keys of a hash.
324
324
 
325
325
  ```ruby
326
- { foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) #=> { bar: 'foo', baz: 'baz' }
327
- { foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
326
+ { foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) #=> { bar: 'foo', baz: 'baz' }
327
+ { foo: 'foo', 'baz' => 'baz' }.rename_keys!(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
328
328
  ```
329
329
 
330
330
  `reverse_merge(!)`
@@ -17,15 +17,6 @@ Returns if a string includes a set of string(s).
17
17
  'example string'.any?('foo', 'string') #=> true
18
18
  ```
19
19
 
20
- `ascii_only(!)`
21
- ------
22
- Replace non-ascii characters.
23
-
24
- ```ruby
25
- '中文123'.ascii_only #=> '123'
26
- '中文123'.ascii_only!('x') #=> 'xx123'
27
- ```
28
-
29
20
  `at`
30
21
  ------
31
22
  Returns the characters at index position, matching string, or regex.
@@ -144,15 +135,6 @@ Splits a string into multiple words and yields its enumeration.
144
135
  'abc. 123'.each_word(&:campitalize!) #=> ['Abc.', '123']
145
136
  ```
146
137
 
147
- `encode_only(!)`
148
- ------
149
- Replace non-encode characters.
150
-
151
- ```ruby
152
- '中文123'.encode_only('UTF-8') #=> '123'
153
- '中文123'.encode_only!('ASCII', 'x') #=> 'xx123'
154
- ```
155
-
156
138
  `ellipsize`
157
139
  ------
158
140
  Truncate a string in the middle.
@@ -432,6 +414,15 @@ Rotate string to the left with count.
432
414
  'example'.rotate(2) #=> 'ampleex'
433
415
  ```
434
416
 
417
+ `safe_encode(!)`
418
+ ------
419
+ Replace non-encode characters.
420
+
421
+ ```ruby
422
+ '中文123'.safe_encode('UTF-8') #=> '123'
423
+ '中文123'.safe_encode!('ASCII', 'x') #=> 'xx123'
424
+ ```
425
+
435
426
  `sample(!)`
436
427
  ------
437
428
  Removes a random value and returns that value.
@@ -4,11 +4,14 @@
4
4
  require "lite/ruby/#{filename}"
5
5
  end
6
6
 
7
+ %w[date time].each do |filename|
8
+ require "lite/ruby/helpers/#{filename}_helper"
9
+ end
10
+
7
11
  %w[
8
12
  array boolean date enumerable hash integer kernel numeric object open_struct range string
9
13
  struct time
10
14
  ].each do |filename|
11
- require "lite/ruby/helpers/#{filename}_helper" if %w[date time].include?(filename)
12
15
  require "lite/ruby/#{filename}"
13
16
  end
14
17
 
@@ -59,6 +59,24 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
59
59
  self[(index(value) + 1) % size]
60
60
  end
61
61
 
62
+ def all_after(value)
63
+ return unless include?(value)
64
+
65
+ i = index(value)
66
+ return if i == (size - 1)
67
+
68
+ self[(i + 1)..-1]
69
+ end
70
+
71
+ def all_before(value)
72
+ return unless include?(value)
73
+
74
+ i = index(value)
75
+ return if i.zero?
76
+
77
+ self[0..(i - 1)]
78
+ end
79
+
62
80
  def before(value)
63
81
  return unless include?(value)
64
82
 
@@ -166,7 +184,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
166
184
  end
167
185
 
168
186
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
169
- def in_groups(number, fill_with = nil)
187
+ def in_groups(number, fill_with = nil, &block)
170
188
  collection_size = size
171
189
  division = collection_size.div(number)
172
190
  modulo = collection_size % number
@@ -181,14 +199,14 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
181
199
  start += grouping
182
200
  end
183
201
 
184
- return collection unless block_given?
202
+ return collection unless defined?(yield)
185
203
 
186
- collection.each { |val| yield(val) }
204
+ collection.each(&block)
187
205
  end
188
206
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
189
207
 
190
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
191
- def in_groups_of(number, fill_with = nil)
208
+ # rubocop:disable Metrics/MethodLength, Style/GuardClause
209
+ def in_groups_of(number, fill_with = nil, &block)
192
210
  if number.to_i <= 0
193
211
  raise ArgumentError, "Group size must be a positive integer, was #{number.inspect}"
194
212
  elsif fill_with == false
@@ -199,11 +217,11 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
199
217
  end
200
218
 
201
219
  sliced_collection = collection.each_slice(number)
202
- return sliced_collection.to_a unless block_given?
220
+ return sliced_collection.to_a unless defined?(yield)
203
221
 
204
- sliced_collection { |val| yield(val) }
222
+ sliced_collection(&block)
205
223
  end
206
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
224
+ # rubocop:enable Metrics/MethodLength, Style/GuardClause
207
225
 
208
226
  def indexes(value)
209
227
  array = []
@@ -293,7 +311,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
293
311
  def split(number = nil)
294
312
  array = [[]]
295
313
 
296
- if block_given?
314
+ if defined?(yield)
297
315
  each { |val| yield(val) ? (array << []) : (array.last << val) }
298
316
  else
299
317
  dup_arr = dup
@@ -332,7 +350,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
332
350
  self[0..position]
333
351
  end
334
352
 
335
- # rubocop:disable Metrics/CyclomaticComplexity
336
353
  def to_sentence(options = {})
337
354
  words_connector = options[:words_connector] || ', '
338
355
  two_words_connector = options[:two_words_connector] || ' and '
@@ -345,7 +362,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
345
362
  else "#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}"
346
363
  end
347
364
  end
348
- # rubocop:enable Metrics/CyclomaticComplexity
349
365
 
350
366
  end
351
367
  end
@@ -20,7 +20,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
20
20
  end
21
21
 
22
22
  def deduce(identity = 0, &block)
23
- if block_given?
23
+ if defined?(yield)
24
24
  map(&block).deduce(identity)
25
25
  else
26
26
  inject { |acc, val| acc - val } || identity
@@ -46,7 +46,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
46
46
  def exactly?(num)
47
47
  found_count = 0
48
48
 
49
- if block_given?
49
+ if defined?(yield)
50
50
  each { |*opt| found_count += 1 if yield(*opt) }
51
51
  else
52
52
  each { |opt| found_count += 1 if opt }
@@ -77,7 +77,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
77
77
  end
78
78
 
79
79
  def exponential(identity = 0, &block)
80
- if block_given?
80
+ if defined?(yield)
81
81
  map(&block).exponential(identity)
82
82
  else
83
83
  inject { |acc, val| acc**val } || identity
@@ -131,7 +131,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
131
131
  def many?
132
132
  found_count = 0
133
133
 
134
- if block_given?
134
+ if defined?(yield)
135
135
  any? do |val|
136
136
  found_count += 1 if yield(val)
137
137
  found_count > 1
@@ -153,7 +153,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
153
153
  end
154
154
  end
155
155
 
156
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
156
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
157
+ # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
157
158
  def occur(amount = nil)
158
159
  result = Hash.new { |hash, key| hash[key] = [] }
159
160
 
@@ -162,7 +163,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
162
163
  result[key] << item
163
164
  end
164
165
 
165
- if block_given?
166
+ if defined?(yield)
166
167
  result.select! { |_key, values| yield(values.size) }
167
168
  else
168
169
  raise ArgumentError, 'Invalid occur amount' unless amount
@@ -176,7 +177,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
176
177
 
177
178
  result.values.flatten.uniq
178
179
  end
179
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
180
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
181
+ # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
180
182
 
181
183
  def pluck(*keys)
182
184
  if keys.many?
@@ -187,7 +189,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
187
189
  end
188
190
 
189
191
  def produce(identity = 0, &block)
190
- if block_given?
192
+ if defined?(yield)
191
193
  map(&block).produce(identity)
192
194
  else
193
195
  inject { |acc, val| acc * val } || identity
@@ -195,7 +197,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
195
197
  end
196
198
 
197
199
  def quotient(identity = 0, &block)
198
- if block_given?
200
+ if defined?(yield)
199
201
  map(&block).quotient(identity)
200
202
  else
201
203
  inject { |acc, val| acc / val } || identity
@@ -205,7 +207,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
205
207
  def several?
206
208
  found_count = 0
207
209
 
208
- if block_given?
210
+ if defined?(yield)
209
211
  each { |*opt| found_count += 1 if yield(*opt) }
210
212
  else
211
213
  each { |opt| found_count += 1 if opt }
@@ -102,7 +102,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
102
102
  end
103
103
  # rubocop:enable Style/GuardClause
104
104
 
105
- # rubocop:disable Metrics/MethodLength
105
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
106
106
  def collate(*others)
107
107
  hash = {}
108
108
 
@@ -121,18 +121,18 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
121
121
  hash.each_value(&:flatten!)
122
122
  hash
123
123
  end
124
- # rubocop:enable Metrics/MethodLength
124
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
125
125
 
126
126
  def collate!(other_hash)
127
127
  replace(collate(other_hash))
128
128
  end
129
129
 
130
- def collect_keys
131
- collect { |key, _| yield(key) }
130
+ def collect_keys(&block)
131
+ keys.map(&block)
132
132
  end
133
133
 
134
- def collect_values
135
- collect { |_, val| yield(val) }
134
+ def collect_values(&block)
135
+ values.map(&block)
136
136
  end
137
137
 
138
138
  def dearray_values(idx = 0)
@@ -186,7 +186,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
186
186
  merge!(other_hash) do |key, this_val, other_val|
187
187
  if this_val.is_a?(Hash) && other_val.is_a?(Hash)
188
188
  this_val.deep_merge(other_val, &block)
189
- elsif block_given?
189
+ elsif defined?(yield)
190
190
  yield(key, this_val, other_val)
191
191
  else
192
192
  other_val
@@ -403,10 +403,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
403
403
  def symbolize_keys
404
404
  each_with_object({}) do |(key, val), hash|
405
405
  new_key = begin
406
- key.to_s.to_sym
407
- rescue StandardError
408
- key
409
- end
406
+ key.to_s.to_sym
407
+ rescue StandardError
408
+ key
409
+ end
410
410
 
411
411
  hash[new_key] = val
412
412
  end
@@ -420,16 +420,16 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
420
420
  def symbolize_and_underscore_keys
421
421
  each_with_object({}) do |(key, val), hash|
422
422
  new_key = begin
423
- key.to_s
424
- .gsub(/::/, '/')
425
- .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
426
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
427
- .tr(' -', '_')
428
- .downcase
429
- .to_sym
430
- rescue StandardError
431
- key
432
- end
423
+ key.to_s
424
+ .gsub(/::/, '/')
425
+ .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
426
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
427
+ .tr(' -', '_')
428
+ .downcase
429
+ .to_sym
430
+ rescue StandardError
431
+ key
432
+ end
433
433
 
434
434
  hash[new_key] = val
435
435
  end
@@ -462,13 +462,13 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
462
462
  end
463
463
 
464
464
  def update_keys
465
- return to_enum(:update_keys) unless block_given?
465
+ return to_enum(:update_keys) unless defined?(yield)
466
466
 
467
467
  replace(each_with_object({}) { |(key, val), hash| hash[yield(key)] = val })
468
468
  end
469
469
 
470
470
  def update_values
471
- return to_enum(:update_values) unless block_given?
471
+ return to_enum(:update_values) unless defined?(yield)
472
472
 
473
473
  replace(each_with_object({}) { |(key, val), hash| hash[key] = yield(val) })
474
474
  end
@@ -86,7 +86,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
86
86
  end
87
87
 
88
88
  def fraction?
89
- fraction != 0.0
89
+ fraction.to_d != 0.0.to_d
90
90
  end
91
91
 
92
92
  def greater_than?(num)
@@ -173,8 +173,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
173
173
  to_s.rjust(precision, pad_number.to_s)
174
174
  end
175
175
 
176
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
177
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
176
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
178
177
  def pad_precision(options = {})
179
178
  pad_number = options[:pad_number] || 0
180
179
  precision = options[:precision] || 2
@@ -191,8 +190,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
191
190
  string[0..(ljust_count - 1)]
192
191
  end
193
192
  end
194
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
195
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
193
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
196
194
 
197
195
  def percentage_of(number)
198
196
  return 0 if zero? || number.zero?
@@ -177,7 +177,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
177
177
  end
178
178
 
179
179
  def try!(*obj, &block)
180
- if obj.empty? && block_given?
180
+ if obj.empty? && defined?(yield)
181
181
  block.arity.zero? ? instance_eval(&block) : yield(self)
182
182
  else
183
183
  public_send(*obj, &block)
@@ -14,7 +14,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
14
14
 
15
15
  hash&.each do |key, val|
16
16
  @table[key.to_sym] = val
17
- new_ostruct_member(key)
17
+ new_ostruct_member!(key)
18
18
  end
19
19
 
20
20
  yield self if block && block.arity == 1
@@ -45,14 +45,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
45
45
  keys.any? { |key| include?(key) }
46
46
  end
47
47
 
48
- def ascii_only(alt = '')
49
- dup.ascii_only!(alt)
50
- end
51
-
52
- def ascii_only!(alt = '')
53
- encode_only!('ASCII', alt)
54
- end
55
-
56
48
  def at(position)
57
49
  self[position]
58
50
  end
@@ -123,7 +115,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
123
115
  end
124
116
 
125
117
  def domain
126
- return self unless self =~ %r{^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)}
118
+ return self unless self =~ %r{^(?:\w+://)?([^/?]+)(?:/|\?|$)}
127
119
 
128
120
  Regexp.last_match(1)
129
121
  end
@@ -136,21 +128,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
136
128
  words.each(&block)
137
129
  end
138
130
 
139
- def encode_only(encoding, alt = '')
140
- dup.encode_only!(encoding, alt)
141
- end
142
-
143
- def encode_only!(encoding, alt = '')
144
- encoding_options = {
145
- invalid: :replace,
146
- undef: :replace,
147
- replace: alt,
148
- UNIVERSAL_NEWLINE_DECORATOR: true
149
- }
150
-
151
- encode!(Encoding.find(encoding), encoding_options)
152
- end
153
-
154
131
  def ellipsize(ellipsize_at, options = {})
155
132
  return self if length <= ellipsize_at
156
133
 
@@ -186,8 +163,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
186
163
  replace(headerize)
187
164
  end
188
165
 
189
- def humanize(options = {})
190
- dup.humanize!(options)
166
+ def humanize(capitalize: true)
167
+ dup.humanize!(capitalize: capitalize)
191
168
  end
192
169
 
193
170
  def humanize!(capitalize: true)
@@ -225,8 +202,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
225
202
  arr_indexes.reverse
226
203
  end
227
204
 
228
- def labelize(options = {})
229
- dup.labelize!(options)
205
+ def labelize(capitalize: true)
206
+ dup.labelize!(capitalize: capitalize)
230
207
  end
231
208
 
232
209
  alias labelcase labelize
@@ -392,7 +369,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
392
369
  b = f
393
370
 
394
371
  if amount.odd?
395
- f = "'" + f
372
+ f = "'#{f}"
396
373
  b += "'"
397
374
  end
398
375
  else
@@ -422,7 +399,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
422
399
  end
423
400
 
424
401
  def remove_tags!
425
- gsub!(%r{<\/?[^>]*>}, '') || self
402
+ gsub!(%r{</?[^>]*>}, '') || self
426
403
  end
427
404
 
428
405
  def rotate(amount = 1)
@@ -434,6 +411,26 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
434
411
  slice!(amount, size - amount) + slice!(0, amount)
435
412
  end
436
413
 
414
+ # rubocop:disable Metrics/MethodLength
415
+ def safe_encode(target_encoding, replacement = '')
416
+ encode(target_encoding)
417
+ rescue Encoding::InvalidByteSequenceError
418
+ force_encoding(target_encoding).scrub!(replacement)
419
+ rescue Encoding::UndefinedConversionError
420
+ encode(
421
+ target_encoding,
422
+ invalid: :replace,
423
+ undef: :replace,
424
+ replace: replacement,
425
+ UNIVERSAL_NEWLINE_DECORATOR: true
426
+ )
427
+ end
428
+ # rubocop:enable Metrics/MethodLength
429
+
430
+ def safe_encode!(target_encoding, replacement = '')
431
+ replace(safe_encode(target_encoding, replacement))
432
+ end
433
+
437
434
  def sample(separator = ' ')
438
435
  split(separator).sample
439
436
  end
@@ -483,7 +480,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
483
480
  gsub!(/[^\x00-\x7F]+/, '')
484
481
  gsub!(/[^\w_ \-]+/i, '')
485
482
  gsub!(/[ \-]+/i, '-')
486
- gsub!(/^\-|\-$/i, '')
483
+ gsub!(/^-|-$/i, '')
487
484
  downcase! || self
488
485
  end
489
486
 
@@ -533,8 +530,9 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
533
530
  def truncate(truncate_at, options = {})
534
531
  return dup unless length > truncate_at
535
532
 
536
- seperator = options[:separator]
537
533
  omission = options[:omission] || '...'
534
+ seperator = options[:separator]
535
+
538
536
  size_with_room_for_omission = truncate_at - omission.length
539
537
 
540
538
  stop = if seperator
@@ -546,13 +544,17 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
546
544
  "#{self[0, stop]}#{omission}"
547
545
  end
548
546
 
547
+ # rubocop:disable Layout/LineLength
549
548
  def truncate_words(words_count, options = {})
550
- sep = options[:separator] || /\s+/
551
- sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
552
- return self unless /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m.match?(self)
549
+ omission = options[:omission] || '...'
550
+ seperator = options[:separator] || /\s+/
551
+
552
+ seperator = Regexp.escape(seperator.to_s) unless seperator.is_a(Regexp)
553
+ return self unless /\A((?:.+?#{seperator}){#{words_count - 1}}.+?)#{seperator}.*/m.match?(self)
553
554
 
554
- "#{::Regexp.last_match(1)}#{options[:omissio] || '...'}"
555
+ "#{::Regexp.last_match(1)}#{omission}"
555
556
  end
557
+ # rubocop:enable Layout/LineLength
556
558
 
557
559
  def underscore
558
560
  dup.underscore!
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.26'
6
+ VERSION ||= '1.0.31'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - j.gomez@drexed.com
128
128
  executables: []
@@ -187,7 +187,7 @@ homepage: http://drexed.github.io/lite-ruby
187
187
  licenses:
188
188
  - MIT
189
189
  metadata: {}
190
- post_install_message:
190
+ post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
193
193
  - lib
@@ -202,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubygems_version: 3.1.3
206
- signing_key:
205
+ rubygems_version: 3.1.4
206
+ signing_key:
207
207
  specification_version: 4
208
208
  summary: Collection of useful Ruby methods for its primitive classes
209
209
  test_files: []