lite-ruby 1.0.27 → 1.0.28

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: bfc486f31bfbbad993a40604cf0334d8f59b5956cf6020f52c5c7140d4e8f114
4
- data.tar.gz: 3b4b5b748b28261e8e602c78cb11e91b546b0c03905c07ac6045a4903f295992
3
+ metadata.gz: fd3026256b8018c856fb0c727be35ddd1821a958e4d15f3473e84537797394c8
4
+ data.tar.gz: 2fde9576e70ea0b7b7a9d6482e05c10e23f1fe8866ccc28d8b82d155332babcd
5
5
  SHA512:
6
- metadata.gz: c9262f97caffc9c198d750cafa76354501df7ef960e6054c8e236a769c9ac26e07a48ee22f68f4e834b9400533f28d35c865f038aa7af0404c8e671735a2baf6
7
- data.tar.gz: fb8058ad49733add958510930473bd26d597432e4aae95c15a77c9aff63847a462cb0fd7d1cfda3a96afb98465c8bc9107c89ba73149482565f836d06e0529ae
6
+ metadata.gz: fb4afea421f458e8c807fca853e7ba889f64ebfab5481735760ae5c12be94a3f812b6004ee06ab87b6227c66a8c5a805ee570e170a9c52216907ec6247ec1f44
7
+ data.tar.gz: 288cb3064bba3feab275aafdd809cdef98e92bfbff0a6d686a87c61552a42f984453c78347b20aebb596b6661fe94b45a1622aec3b057de1fb9368e0d9071f39
@@ -59,5 +59,7 @@ Style/RedundantRegexpCharacterClass:
59
59
  Enabled: true
60
60
  Style/RedundantRegexpEscape:
61
61
  Enabled: true
62
+ Style/RedundantFetchBlock:
63
+ Enabled: true
62
64
  Style/SlicingWithRange:
63
65
  Enabled: false
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.28] - 2020-06-25
10
+ # Changed
11
+ - Rename String => `encode_only` to `safe_encode`
12
+ # Removed
13
+ - Remove String => `ascii_only`
14
+
9
15
  ## [1.0.26] - 2020-06-12
10
16
  ### Added
11
17
  - Added array => `all_after`
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.27)
4
+ lite-ruby (1.0.28)
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.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.1)
17
- activesupport (= 6.0.3.1)
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.1)
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)
@@ -30,7 +30,7 @@ GEM
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.2)
34
34
  erubi (1.9.0)
35
35
  fasterer (0.8.3)
36
36
  colorize (~> 0.7)
@@ -40,7 +40,7 @@ GEM
40
40
  railties (>= 3.0.0)
41
41
  i18n (1.8.3)
42
42
  concurrent-ruby (~> 1.0)
43
- loofah (2.5.0)
43
+ loofah (2.6.0)
44
44
  crass (~> 1.0.2)
45
45
  nokogiri (>= 1.5.9)
46
46
  method_source (1.0.0)
@@ -48,10 +48,10 @@ GEM
48
48
  minitest (5.14.1)
49
49
  nokogiri (1.10.9)
50
50
  mini_portile2 (~> 2.4.0)
51
- parallel (1.19.1)
52
- parser (2.7.1.3)
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,9 +59,9 @@ 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.2)
63
+ actionpack (= 6.0.3.2)
64
+ activesupport (= 6.0.3.2)
65
65
  method_source
66
66
  rake (>= 0.8.7)
67
67
  thor (>= 0.20.3, < 2.0)
@@ -82,13 +82,13 @@ GEM
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.85.1)
85
+ rubocop (0.86.0)
86
86
  parallel (~> 1.10)
87
87
  parser (>= 2.7.0.1)
88
88
  rainbow (>= 2.2.2, < 4.0)
89
89
  regexp_parser (>= 1.7)
90
90
  rexml
91
- rubocop-ast (>= 0.0.3)
91
+ rubocop-ast (>= 0.0.3, < 1.0)
92
92
  ruby-progressbar (~> 1.7)
93
93
  unicode-display_width (>= 1.4.0, < 2.0)
94
94
  rubocop-ast (0.0.3)
@@ -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.
@@ -350,7 +350,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
350
350
  self[0..position]
351
351
  end
352
352
 
353
- # rubocop:disable Metrics/CyclomaticComplexity
354
353
  def to_sentence(options = {})
355
354
  words_connector = options[:words_connector] || ', '
356
355
  two_words_connector = options[:two_words_connector] || ' and '
@@ -363,7 +362,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
363
362
  else "#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}"
364
363
  end
365
364
  end
366
- # rubocop:enable Metrics/CyclomaticComplexity
367
365
 
368
366
  end
369
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))
@@ -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?
@@ -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
@@ -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
 
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.27'
6
+ VERSION ||= '1.0.28'
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.27
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler