lite-ruby 1.0.24 → 1.0.29

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: 6ab807277ec08dcba4afc47272746223b154fbfc66dcb27d32594f808d26339e
4
- data.tar.gz: 9b06a59c0122c2b97285193d11476bade1fc50e69f9f414a06dcdf84fc65a637
3
+ metadata.gz: ab408998ca8693b60da98a82162403e2c18a30d22974a17ec17e3e7c38c9ad04
4
+ data.tar.gz: 1a34293ee4ea051a3308d67eb77011902b6f7389284d695d510c54b48e449476
5
5
  SHA512:
6
- metadata.gz: a795dd8081eaa3172294a1c76f647c0008ebc81f39d70e7785aa9942cd19b542c10513ce04ddecc3b01b3ab3d65ac492307d8e96cd0574239fb4d29a91039284
7
- data.tar.gz: 1fff8bfcab78ccf1c0b0f63d3761a4f8c0b08fa61cd4c24964a664fb393f3ea7d50487e21567bc8a0b55bea71d02c1c97c02ce6f75e27cc6713d81500714b880
6
+ metadata.gz: 0d1a2fd4da82dfb787b672e13b2be1289544f7a969b29a84b69f2a1bc01a59727c9a530d9fbfe51d3ef186cc27782582f841e748acaaa3e769c6de1d34086dc5
7
+ data.tar.gz: 1a1926a5a3ab3f49865ccf81ba70212806cc02b766e811da0715fc11d5ffbfce823d5a7820efe6a2f428140cd168fd164961aec4b72482cf1976ee8e425908c4
@@ -2,12 +2,15 @@ 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
8
9
  Layout/EmptyLinesAroundBlockBody:
9
10
  Exclude:
10
11
  - 'spec/**/**/*'
12
+ Layout/EmptyLinesAroundAttributeAccessor:
13
+ Enabled: true
11
14
  Layout/EmptyLinesAroundClassBody:
12
15
  EnforcedStyle: empty_lines_except_namespace
13
16
  Layout/EmptyLinesAroundModuleBody:
@@ -16,6 +19,10 @@ Layout/LineLength:
16
19
  Max: 100
17
20
  Layout/SpaceAroundMethodCallOperator:
18
21
  Enabled: true
22
+ Lint/DeprecatedOpenSSLConstant:
23
+ Enabled: true
24
+ Lint/MixedRegexpCaptureTypes:
25
+ Enabled: true
19
26
  Lint/RaiseException:
20
27
  Enabled: true
21
28
  Lint/StructNewOverride:
@@ -49,3 +56,11 @@ Style/HashTransformValues:
49
56
  Enabled: false
50
57
  Style/PerlBackrefs:
51
58
  Enabled: false
59
+ Style/RedundantRegexpCharacterClass:
60
+ Enabled: true
61
+ Style/RedundantRegexpEscape:
62
+ Enabled: true
63
+ Style/RedundantFetchBlock:
64
+ Enabled: true
65
+ Style/SlicingWithRange:
66
+ 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,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.29] - 2020-07-03
10
+ ### Added
11
+ - Added Ruby 2.7 support
12
+
13
+ ## [1.0.28] - 2020-06-25
14
+ # Changed
15
+ - Rename String => `encode_only` to `safe_encode`
16
+ # Removed
17
+ - Remove String => `ascii_only`
18
+
19
+ ## [1.0.26] - 2020-06-12
20
+ ### Added
21
+ - Added array => `all_after`
22
+ - Added array => `all_before`
23
+
24
+ ## [1.0.26] - 2020-05-22
25
+ ### Changed
26
+ - Changed hash `to_open_struct` and `to_object` to be independent methods
27
+
28
+ ## [1.0.25] - 2020-05-20
29
+ ### Added
30
+ - Added Hash => `to_open_struct`
31
+ - Added Hash => `to_struct`
32
+ - Added OpenStruct => `to_hash`
33
+ - Added OpenStruct => `to_json(table: true)`
34
+
9
35
  ## [1.0.24] - 2020-05-07
10
36
  ### Added
11
37
  - Added Object => `salvage_try`
@@ -1,36 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.24)
4
+ lite-ruby (1.0.29)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.0.3)
10
- actionview (= 6.0.3)
11
- activesupport (= 6.0.3)
9
+ actionpack (6.0.3.2)
10
+ actionview (= 6.0.3.2)
11
+ activesupport (= 6.0.3.2)
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)
17
- activesupport (= 6.0.3)
16
+ actionview (6.0.3.2)
17
+ activesupport (= 6.0.3.2)
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)
22
+ activesupport (6.0.3.2)
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
31
  concurrent-ruby (1.1.6)
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,21 +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.3)
42
42
  concurrent-ruby (~> 1.0)
43
- jaro_winkler (1.5.4)
44
- loofah (2.5.0)
43
+ loofah (2.6.0)
45
44
  crass (~> 1.0.2)
46
45
  nokogiri (>= 1.5.9)
47
46
  method_source (1.0.0)
48
47
  mini_portile2 (2.4.0)
49
- minitest (5.14.0)
48
+ minitest (5.14.1)
50
49
  nokogiri (1.10.9)
51
50
  mini_portile2 (~> 2.4.0)
52
- parallel (1.19.1)
53
- parser (2.7.1.2)
54
- ast (~> 2.4.0)
55
- 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)
56
55
  rack-test (1.1.0)
57
56
  rack (>= 1.0, < 3)
58
57
  rails-dom-testing (2.0.3)
@@ -60,14 +59,15 @@ GEM
60
59
  nokogiri (>= 1.6)
61
60
  rails-html-sanitizer (1.3.0)
62
61
  loofah (~> 2.3)
63
- railties (6.0.3)
64
- actionpack (= 6.0.3)
65
- activesupport (= 6.0.3)
62
+ railties (6.0.3.2)
63
+ actionpack (= 6.0.3.2)
64
+ activesupport (= 6.0.3.2)
66
65
  method_source
67
66
  rake (>= 0.8.7)
68
67
  thor (>= 0.20.3, < 2.0)
69
68
  rainbow (3.0.0)
70
69
  rake (13.0.1)
70
+ regexp_parser (1.7.1)
71
71
  rexml (3.2.4)
72
72
  rspec (3.9.0)
73
73
  rspec-core (~> 3.9.0)
@@ -75,35 +75,38 @@ GEM
75
75
  rspec-mocks (~> 3.9.0)
76
76
  rspec-core (3.9.2)
77
77
  rspec-support (~> 3.9.3)
78
- rspec-expectations (3.9.1)
78
+ rspec-expectations (3.9.2)
79
79
  diff-lcs (>= 1.2.0, < 2.0)
80
80
  rspec-support (~> 3.9.0)
81
81
  rspec-mocks (3.9.1)
82
82
  diff-lcs (>= 1.2.0, < 2.0)
83
83
  rspec-support (~> 3.9.0)
84
84
  rspec-support (3.9.3)
85
- rubocop (0.82.0)
86
- jaro_winkler (~> 1.5.1)
85
+ rubocop (0.86.0)
87
86
  parallel (~> 1.10)
88
87
  parser (>= 2.7.0.1)
89
88
  rainbow (>= 2.2.2, < 4.0)
89
+ regexp_parser (>= 1.7)
90
90
  rexml
91
+ rubocop-ast (>= 0.0.3, < 1.0)
91
92
  ruby-progressbar (~> 1.7)
92
93
  unicode-display_width (>= 1.4.0, < 2.0)
93
- rubocop-performance (1.5.2)
94
+ rubocop-ast (0.1.0)
95
+ parser (>= 2.7.0.1)
96
+ rubocop-performance (1.6.1)
94
97
  rubocop (>= 0.71.0)
95
- rubocop-rspec (1.39.0)
98
+ rubocop-rspec (1.41.0)
96
99
  rubocop (>= 0.68.1)
97
100
  ruby-progressbar (1.10.1)
98
101
  ruby_parser (3.14.2)
99
102
  sexp_processor (~> 4.9)
100
- sexp_processor (4.14.1)
103
+ sexp_processor (4.15.0)
101
104
  thor (1.0.1)
102
105
  thread_safe (0.3.6)
103
106
  tzinfo (1.2.7)
104
107
  thread_safe (~> 0.1)
105
108
  unicode-display_width (1.7.0)
106
- zeitwerk (2.3.0)
109
+ zeitwerk (2.3.1)
107
110
 
108
111
  PLATFORMS
109
112
  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.
@@ -427,10 +427,29 @@ Symbolize and underscore hash keys.
427
427
 
428
428
  `to_object` aka `to_o`
429
429
  ------
430
- Converts an object to have an object like API.
430
+ Converts a hash and all nested hashes to open structs.
431
431
 
432
432
  ```ruby
433
433
  { foo: { bar: true } }.to_object.foo.bar #=> true
434
+ { foo: { bar: true } }.to_object.foo.bax #=> nil
435
+ ```
436
+
437
+ `to_open_struct`
438
+ ------
439
+ Converts a hash to an open struct to have an object like API.
440
+
441
+ ```ruby
442
+ { foo: { bar: true } }.to_open_struct.foo #=> { bar: true }
443
+ { foo: { bar: true } }.to_open_struct.bax #=> nil
444
+ ```
445
+
446
+ `to_struct`
447
+ ------
448
+ Converts a hash to a struct to have an object like API.
449
+
450
+ ```ruby
451
+ { foo: { bar: true } }.to_struct.foo #=> { bar: true }
452
+ { foo: { bar: true } }.to_struct.bax #=> Raises error
434
453
  ```
435
454
 
436
455
  `update_each`
@@ -31,7 +31,7 @@ person['name'] = 'tim'
31
31
 
32
32
  `attributes`
33
33
  ------
34
- Returns the key values of the assigned struct.
34
+ Returns the key values as a hash of the assigned struct.
35
35
 
36
36
  ```ruby
37
37
  person = OpenStruct.new(name: 'bob', age: 60)
@@ -49,3 +49,25 @@ person = OpenStruct.new(name: 'bob', age: 60)
49
49
  person.replace(name: 'tom', age: 28)
50
50
  preson.name #=> 'tom'
51
51
  ```
52
+
53
+ `to_hash` aka `to_h`
54
+ ------
55
+ Returns the key values as a hash of the assigned struct.
56
+
57
+ ```ruby
58
+ person = OpenStruct.new(name: 'bob', age: 60)
59
+
60
+ person.to_hash #=> { table: { name: 'bob', age: 60 } }
61
+ person.to_hash(table: false) #=> { name: 'bob', age: 60 }
62
+ ```
63
+
64
+ `to_json` aka `as_json`
65
+ ------
66
+ Returns the key values as Json of the assigned struct.
67
+
68
+ ```ruby
69
+ person = OpenStruct.new(name: 'bob', age: 60)
70
+
71
+ person.to_json #=> { table: { name: 'bob', age: 60 } }
72
+ person.to_json(table: false) #=> { name: 'bob', age: 60 }
73
+ ```
@@ -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.
@@ -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
 
@@ -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
@@ -153,7 +153,7 @@ 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, Metrics/MethodLength
157
157
  def occur(amount = nil)
158
158
  result = Hash.new { |hash, key| hash[key] = [] }
159
159
 
@@ -176,7 +176,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
176
176
 
177
177
  result.values.flatten.uniq
178
178
  end
179
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
179
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
180
180
 
181
181
  def pluck(*keys)
182
182
  if keys.many?
@@ -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/CyclomaticComplexity, Metrics/MethodLength
106
106
  def collate(*others)
107
107
  hash = {}
108
108
 
@@ -121,7 +121,7 @@ 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/CyclomaticComplexity, Metrics/MethodLength
125
125
 
126
126
  def collate!(other_hash)
127
127
  replace(collate(other_hash))
@@ -446,6 +446,17 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
446
446
 
447
447
  alias to_o to_object
448
448
 
449
+ def to_open_struct(lazy: true)
450
+ struct = OpenStruct.new(self)
451
+ struct.methods(lazy)
452
+ struct
453
+ end
454
+
455
+ def to_struct
456
+ struct = Struct.new(*keys)
457
+ struct.new(*values)
458
+ end
459
+
449
460
  def update_each
450
461
  replace(each_with_object({}) { |(key, val), hash| hash.update(yield(key, val)) })
451
462
  end
@@ -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, Metrics/PerceivedComplexity
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, Metrics/PerceivedComplexity
196
194
 
197
195
  def percentage_of(number)
198
196
  return 0 if zero? || number.zero?
@@ -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
@@ -33,12 +33,26 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
33
33
  end
34
34
 
35
35
  def attributes
36
- each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
36
+ @table
37
37
  end
38
38
 
39
39
  def replace(args)
40
40
  args.each_pair { |key, val| send("#{key}=", val) }
41
41
  end
42
42
 
43
+ def to_hash(table: true)
44
+ return attributes unless table
45
+
46
+ { table: attributes }
47
+ end
48
+
49
+ alias to_h to_hash
50
+
51
+ def to_json(table: true)
52
+ to_hash(table: table).to_json
53
+ end
54
+
55
+ alias as_json to_json
56
+
43
57
  end
44
58
  end
@@ -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
 
@@ -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
@@ -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
 
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.24'
6
+ VERSION ||= '1.0.29'
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.24
4
+ version: 1.0.29
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-07 00:00:00.000000000 Z
11
+ date: 2020-07-03 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.2
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: []