lite-ruby 1.0.25 → 1.0.30
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/.rubocop.yml +12 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile.lock +28 -23
- data/docs/ARRAY.md +25 -5
- data/docs/HASH.md +13 -2
- data/docs/STRING.md +9 -18
- data/lib/lite/ruby/array.rb +18 -2
- data/lib/lite/ruby/enumerable.rb +2 -2
- data/lib/lite/ruby/hash.rb +10 -5
- data/lib/lite/ruby/numeric.rb +2 -4
- data/lib/lite/ruby/open_struct.rb +1 -1
- data/lib/lite/ruby/string.rb +37 -35
- data/lib/lite/ruby/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 497a85ac4bea67a37f713e049589a1825e1ea9c2cb157ad5b9aba5b89ed0c37e
|
4
|
+
data.tar.gz: 7f4747cdcff9975cec2d43cb929223bb26ca43939ab60a3dee46d378252fdabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f63e2c228b2e4eb349a4b9c14187e906f3bb5803ea7188a352c4bbc6f82ac2867148b68acd92e8c5a758d9e57943f9410c72d380295953fa8e741b0734e3260
|
7
|
+
data.tar.gz: c1416d519e4ec7d8a3c0fad863145789cc55a262d293bacc9df6927ecc92d04b3464eee778dede669a33ecafdca6e2c4f51b725ffdc76735ec16c7a730447eac
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,8 @@ require:
|
|
2
2
|
- rubocop-performance
|
3
3
|
- rubocop-rspec
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion: 2.
|
5
|
+
TargetRubyVersion: 2.7
|
6
|
+
NewCops: enable
|
6
7
|
DisplayCopNames: true
|
7
8
|
DisplayStyleGuide: true
|
8
9
|
Layout/EmptyLinesAroundBlockBody:
|
@@ -18,6 +19,10 @@ Layout/LineLength:
|
|
18
19
|
Max: 100
|
19
20
|
Layout/SpaceAroundMethodCallOperator:
|
20
21
|
Enabled: true
|
22
|
+
Lint/DeprecatedOpenSSLConstant:
|
23
|
+
Enabled: true
|
24
|
+
Lint/MixedRegexpCaptureTypes:
|
25
|
+
Enabled: true
|
21
26
|
Lint/RaiseException:
|
22
27
|
Enabled: true
|
23
28
|
Lint/StructNewOverride:
|
@@ -51,5 +56,11 @@ Style/HashTransformValues:
|
|
51
56
|
Enabled: false
|
52
57
|
Style/PerlBackrefs:
|
53
58
|
Enabled: false
|
59
|
+
Style/RedundantRegexpCharacterClass:
|
60
|
+
Enabled: true
|
61
|
+
Style/RedundantRegexpEscape:
|
62
|
+
Enabled: true
|
63
|
+
Style/RedundantFetchBlock:
|
64
|
+
Enabled: true
|
54
65
|
Style/SlicingWithRange:
|
55
66
|
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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.30] - 2020-07-03
|
10
|
+
### Added
|
11
|
+
- Added more Ruby 2.7 support
|
12
|
+
|
13
|
+
## [1.0.29] - 2020-07-03
|
14
|
+
### Added
|
15
|
+
- Added Ruby 2.7 support
|
16
|
+
|
17
|
+
## [1.0.28] - 2020-06-25
|
18
|
+
# Changed
|
19
|
+
- Rename String => `encode_only` to `safe_encode`
|
20
|
+
# Removed
|
21
|
+
- Remove String => `ascii_only`
|
22
|
+
|
23
|
+
## [1.0.26] - 2020-06-12
|
24
|
+
### Added
|
25
|
+
- Added array => `all_after`
|
26
|
+
- Added array => `all_before`
|
27
|
+
|
28
|
+
## [1.0.26] - 2020-05-22
|
29
|
+
### Changed
|
30
|
+
- Changed hash `to_open_struct` and `to_object` to be independent methods
|
31
|
+
|
9
32
|
## [1.0.25] - 2020-05-20
|
10
33
|
### Added
|
11
34
|
- Added Hash => `to_open_struct`
|
data/Gemfile.lock
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (1.0.
|
4
|
+
lite-ruby (1.0.30)
|
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.
|
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.
|
33
|
+
diff-lcs (1.4.4)
|
34
34
|
erubi (1.9.0)
|
35
35
|
fasterer (0.8.3)
|
36
36
|
colorize (~> 0.7)
|
@@ -38,9 +38,9 @@ GEM
|
|
38
38
|
generator_spec (0.9.4)
|
39
39
|
activesupport (>= 3.0.0)
|
40
40
|
railties (>= 3.0.0)
|
41
|
-
i18n (1.8.
|
41
|
+
i18n (1.8.3)
|
42
42
|
concurrent-ruby (~> 1.0)
|
43
|
-
loofah (2.
|
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.
|
52
|
-
parser (2.7.1.
|
53
|
-
ast (~> 2.4.
|
54
|
-
rack (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.
|
63
|
-
actionpack (= 6.0.3.
|
64
|
-
activesupport (= 6.0.3.
|
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)
|
68
68
|
rainbow (3.0.0)
|
69
69
|
rake (13.0.1)
|
70
|
+
regexp_parser (1.7.1)
|
70
71
|
rexml (3.2.4)
|
71
72
|
rspec (3.9.0)
|
72
73
|
rspec-core (~> 3.9.0)
|
@@ -81,27 +82,31 @@ 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.
|
85
|
+
rubocop (0.86.0)
|
85
86
|
parallel (~> 1.10)
|
86
87
|
parser (>= 2.7.0.1)
|
87
88
|
rainbow (>= 2.2.2, < 4.0)
|
89
|
+
regexp_parser (>= 1.7)
|
88
90
|
rexml
|
91
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
89
92
|
ruby-progressbar (~> 1.7)
|
90
93
|
unicode-display_width (>= 1.4.0, < 2.0)
|
91
|
-
rubocop-
|
94
|
+
rubocop-ast (0.1.0)
|
95
|
+
parser (>= 2.7.0.1)
|
96
|
+
rubocop-performance (1.6.1)
|
92
97
|
rubocop (>= 0.71.0)
|
93
|
-
rubocop-rspec (1.
|
98
|
+
rubocop-rspec (1.41.0)
|
94
99
|
rubocop (>= 0.68.1)
|
95
100
|
ruby-progressbar (1.10.1)
|
96
101
|
ruby_parser (3.14.2)
|
97
102
|
sexp_processor (~> 4.9)
|
98
|
-
sexp_processor (4.
|
103
|
+
sexp_processor (4.15.0)
|
99
104
|
thor (1.0.1)
|
100
105
|
thread_safe (0.3.6)
|
101
106
|
tzinfo (1.2.7)
|
102
107
|
thread_safe (~> 0.1)
|
103
108
|
unicode-display_width (1.7.0)
|
104
|
-
zeitwerk (2.3.
|
109
|
+
zeitwerk (2.3.1)
|
105
110
|
|
106
111
|
PLATFORMS
|
107
112
|
ruby
|
data/docs/ARRAY.md
CHANGED
@@ -64,14 +64,24 @@ Returns the value after a given value.
|
|
64
64
|
['1', '2', '3'].after('4') #=> nil
|
65
65
|
```
|
66
66
|
|
67
|
-
`
|
67
|
+
`all_after`
|
68
68
|
------
|
69
|
-
|
69
|
+
Returns all values after a given value.
|
70
70
|
|
71
71
|
```ruby
|
72
|
-
['1',
|
73
|
-
['1',
|
74
|
-
['1',
|
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.
|
data/docs/HASH.md
CHANGED
@@ -425,12 +425,22 @@ Symbolize and underscore hash keys.
|
|
425
425
|
{ 'firstName' => 'foo', 'last Name' => 'test' }.symbolize_and_underscore_keys #=> { first_name: 'foo', last_name: 'test' }
|
426
426
|
```
|
427
427
|
|
428
|
-
`
|
428
|
+
`to_object` aka `to_o`
|
429
|
+
------
|
430
|
+
Converts a hash and all nested hashes to open structs.
|
431
|
+
|
432
|
+
```ruby
|
433
|
+
{ foo: { bar: true } }.to_object.foo.bar #=> true
|
434
|
+
{ foo: { bar: true } }.to_object.foo.bax #=> nil
|
435
|
+
```
|
436
|
+
|
437
|
+
`to_open_struct`
|
429
438
|
------
|
430
439
|
Converts a hash to an open struct to have an object like API.
|
431
440
|
|
432
441
|
```ruby
|
433
|
-
{ foo: { bar: true } }.to_open_struct.foo
|
442
|
+
{ foo: { bar: true } }.to_open_struct.foo #=> { bar: true }
|
443
|
+
{ foo: { bar: true } }.to_open_struct.bax #=> nil
|
434
444
|
```
|
435
445
|
|
436
446
|
`to_struct`
|
@@ -439,6 +449,7 @@ Converts a hash to a struct to have an object like API.
|
|
439
449
|
|
440
450
|
```ruby
|
441
451
|
{ foo: { bar: true } }.to_struct.foo #=> { bar: true }
|
452
|
+
{ foo: { bar: true } }.to_struct.bax #=> Raises error
|
442
453
|
```
|
443
454
|
|
444
455
|
`update_each`
|
data/docs/STRING.md
CHANGED
@@ -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.
|
data/lib/lite/ruby/array.rb
CHANGED
@@ -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
|
data/lib/lite/ruby/enumerable.rb
CHANGED
@@ -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?
|
data/lib/lite/ruby/hash.rb
CHANGED
@@ -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))
|
@@ -440,12 +440,17 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
|
|
440
440
|
replace(symbolize_and_underscore_keys)
|
441
441
|
end
|
442
442
|
|
443
|
-
def
|
443
|
+
def to_object
|
444
444
|
JSON.parse(to_json, object_class: OpenStruct)
|
445
445
|
end
|
446
446
|
|
447
|
-
alias to_object
|
448
|
-
|
447
|
+
alias to_o to_object
|
448
|
+
|
449
|
+
def to_open_struct(lazy: true)
|
450
|
+
struct = OpenStruct.new(self)
|
451
|
+
struct.methods(lazy)
|
452
|
+
struct
|
453
|
+
end
|
449
454
|
|
450
455
|
def to_struct
|
451
456
|
struct = Struct.new(*keys)
|
data/lib/lite/ruby/numeric.rb
CHANGED
@@ -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/
|
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/
|
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?
|
data/lib/lite/ruby/string.rb
CHANGED
@@ -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(
|
190
|
-
dup.humanize!(
|
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(
|
229
|
-
dup.labelize!(
|
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{
|
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!(
|
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
|
-
|
551
|
-
|
552
|
-
|
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)}#{
|
555
|
+
"#{::Regexp.last_match(1)}#{omission}"
|
555
556
|
end
|
557
|
+
# rubocop:enable Layout/LineLength
|
556
558
|
|
557
559
|
def underscore
|
558
560
|
dup.underscore!
|
data/lib/lite/ruby/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.30
|
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-
|
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.
|
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: []
|