lite-ruby 1.0.31 → 1.1.0
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 +2 -0
- data/CHANGELOG.md +15 -2
- data/Gemfile.lock +33 -32
- data/README.md +1 -0
- data/docs/ARRAY.md +2 -10
- data/docs/HASH.md +2 -2
- data/docs/NUMERIC.md +0 -10
- data/docs/STRING.md +2 -2
- data/docs/TIME.md +17 -17
- data/lib/lite/ruby/array.rb +15 -100
- data/lib/lite/ruby/boolean.rb +4 -4
- data/lib/lite/ruby/enumerable.rb +4 -40
- data/lib/lite/ruby/hash.rb +23 -97
- data/lib/lite/ruby/helpers/time_helper.rb +21 -21
- data/lib/lite/ruby/numeric.rb +10 -33
- data/lib/lite/ruby/object.rb +4 -38
- data/lib/lite/ruby/open_struct.rb +1 -2
- data/lib/lite/ruby/range.rb +2 -4
- data/lib/lite/ruby/safe/array.rb +93 -0
- data/lib/lite/ruby/safe/enumerable.rb +42 -0
- data/lib/lite/ruby/safe/hash.rb +83 -0
- data/lib/lite/ruby/safe/object.rb +41 -0
- data/lib/lite/ruby/safe/range.rb +9 -0
- data/lib/lite/ruby/safe/string.rb +187 -0
- data/lib/lite/ruby/string.rb +39 -194
- data/lib/lite/ruby/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 706904db37834627c1356104bc628510a7aa144278306c0cdb8a95594204444a
|
4
|
+
data.tar.gz: 5aac1bf1134a94b67dca8d577396f5da9f4f1f35c294040412c1ac3c49f2a3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1241428618317da93171051ef4ec7ff613f8db822d1514c71653f5d591067eb787fa6bd88b5a9462020fa6a0116edf3e064462996ca8f6734da52c8031102317
|
7
|
+
data.tar.gz: 2fe2fca36eec6f76495fcef11e57f1dc75153a36c642225e613a43bb97defc28d803aeb78063b4459e9ebd426277f803baf8e3f6c3eecdd32d47fba94ec50b4b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.1.0] - 2020-11-06
|
10
|
+
### Added
|
11
|
+
- Added Array => `extract!` to `except!` alias
|
12
|
+
- Added Array => `only(!)` to `select_values(!)` alias
|
13
|
+
- Added Hash => `collect_keys` to `map_keys` alias
|
14
|
+
- Added Hash => `collect_values` to `map_values` alias
|
15
|
+
### Changed
|
16
|
+
- Rename Date, Time => `[method_name]_12` to `[method_name]12` ex: `hour_12` is now `hour12`
|
17
|
+
- Rename String => `transliterize` to `transliterate`
|
18
|
+
- Skip loading clashing methods with active support
|
19
|
+
### Remove
|
20
|
+
- Numeric `clamp`
|
21
|
+
|
9
22
|
## [1.0.31] - 2020-09-21
|
10
23
|
### Changed
|
11
24
|
- Changed `block_given?` => `defined?(yield)` for more performance
|
@@ -26,8 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
26
39
|
|
27
40
|
## [1.0.26] - 2020-06-12
|
28
41
|
### Added
|
29
|
-
- Added
|
30
|
-
- Added
|
42
|
+
- Added Array => `all_after`
|
43
|
+
- Added Array => `all_before`
|
31
44
|
|
32
45
|
## [1.0.26] - 2020-05-22
|
33
46
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (1.0
|
4
|
+
lite-ruby (1.1.0)
|
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.4)
|
10
|
+
actionview (= 6.0.3.4)
|
11
|
+
activesupport (= 6.0.3.4)
|
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.4)
|
17
|
+
activesupport (= 6.0.3.4)
|
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.4)
|
23
23
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
24
|
i18n (>= 0.7, < 2)
|
25
25
|
minitest (~> 5.1)
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
nokogiri (1.10.10)
|
50
50
|
mini_portile2 (~> 2.4.0)
|
51
51
|
parallel (1.19.2)
|
52
|
-
parser (2.7.
|
52
|
+
parser (2.7.2.0)
|
53
53
|
ast (~> 2.4.1)
|
54
54
|
rack (2.2.3)
|
55
55
|
rack-test (1.1.0)
|
@@ -59,45 +59,46 @@ 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.4)
|
63
|
+
actionpack (= 6.0.3.4)
|
64
|
+
activesupport (= 6.0.3.4)
|
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.
|
70
|
+
regexp_parser (1.8.2)
|
71
71
|
rexml (3.2.4)
|
72
|
-
rspec (3.
|
73
|
-
rspec-core (~> 3.
|
74
|
-
rspec-expectations (~> 3.
|
75
|
-
rspec-mocks (~> 3.
|
76
|
-
rspec-core (3.
|
77
|
-
rspec-support (~> 3.
|
78
|
-
rspec-expectations (3.
|
72
|
+
rspec (3.10.0)
|
73
|
+
rspec-core (~> 3.10.0)
|
74
|
+
rspec-expectations (~> 3.10.0)
|
75
|
+
rspec-mocks (~> 3.10.0)
|
76
|
+
rspec-core (3.10.0)
|
77
|
+
rspec-support (~> 3.10.0)
|
78
|
+
rspec-expectations (3.10.0)
|
79
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
-
rspec-support (~> 3.
|
81
|
-
rspec-mocks (3.
|
80
|
+
rspec-support (~> 3.10.0)
|
81
|
+
rspec-mocks (3.10.0)
|
82
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
-
rspec-support (~> 3.
|
84
|
-
rspec-support (3.
|
85
|
-
rubocop (
|
83
|
+
rspec-support (~> 3.10.0)
|
84
|
+
rspec-support (3.10.0)
|
85
|
+
rubocop (1.2.0)
|
86
86
|
parallel (~> 1.10)
|
87
|
-
parser (>= 2.7.1.
|
87
|
+
parser (>= 2.7.1.5)
|
88
88
|
rainbow (>= 2.2.2, < 4.0)
|
89
|
-
regexp_parser (>= 1.
|
89
|
+
regexp_parser (>= 1.8)
|
90
90
|
rexml
|
91
|
-
rubocop-ast (>= 0.
|
91
|
+
rubocop-ast (>= 1.0.1)
|
92
92
|
ruby-progressbar (~> 1.7)
|
93
93
|
unicode-display_width (>= 1.4.0, < 2.0)
|
94
|
-
rubocop-ast (
|
95
|
-
parser (>= 2.7.1.
|
94
|
+
rubocop-ast (1.1.1)
|
95
|
+
parser (>= 2.7.1.5)
|
96
96
|
rubocop-performance (1.8.1)
|
97
97
|
rubocop (>= 0.87.0)
|
98
98
|
rubocop-ast (>= 0.4.0)
|
99
|
-
rubocop-rspec (
|
100
|
-
rubocop (~> 0
|
99
|
+
rubocop-rspec (2.0.0)
|
100
|
+
rubocop (~> 1.0)
|
101
|
+
rubocop-ast (>= 1.1.0)
|
101
102
|
ruby-progressbar (1.10.1)
|
102
103
|
ruby_parser (3.15.0)
|
103
104
|
sexp_processor (~> 4.9)
|
@@ -107,7 +108,7 @@ GEM
|
|
107
108
|
tzinfo (1.2.7)
|
108
109
|
thread_safe (~> 0.1)
|
109
110
|
unicode-display_width (1.7.0)
|
110
|
-
zeitwerk (2.4.
|
111
|
+
zeitwerk (2.4.1)
|
111
112
|
|
112
113
|
PLATFORMS
|
113
114
|
ruby
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[](https://travis-ci.org/drexed/lite-ruby)
|
5
5
|
|
6
6
|
Lite::Ruby is a collection of useful Ruby methods for its primitive classes.
|
7
|
+
AcitveSupport equivalent methods do not get included when AcitveSupport is available.
|
7
8
|
|
8
9
|
**NOTE:** If you are coming from `ActiveObject`, please read the [port](#port) section.
|
9
10
|
|
data/docs/ARRAY.md
CHANGED
@@ -155,7 +155,7 @@ Returns a list of duplicate elements.
|
|
155
155
|
[1, 1, 2, 2, 2, 3].duplicates(3) #=> [2]
|
156
156
|
```
|
157
157
|
|
158
|
-
`except(!)`
|
158
|
+
`except(!)` aka `remove_values(!)`
|
159
159
|
------
|
160
160
|
Removes given values from the array.
|
161
161
|
|
@@ -235,7 +235,7 @@ Converts blank values into `nil`.
|
|
235
235
|
['', 3, 4].nillify! #=> [nil, 3, 4]
|
236
236
|
```
|
237
237
|
|
238
|
-
`only(!)`
|
238
|
+
`only(!)` aka `select_values(!)`
|
239
239
|
------
|
240
240
|
Selects given values from the array.
|
241
241
|
|
@@ -285,14 +285,6 @@ Returns a sample of random n values by size or given.
|
|
285
285
|
[1, 2, 3].rand_sample(1) #=> [2]
|
286
286
|
```
|
287
287
|
|
288
|
-
`reject_values`
|
289
|
-
------
|
290
|
-
Delete multiple values from a `dup` copy of the original array.
|
291
|
-
|
292
|
-
```ruby
|
293
|
-
[1, 2, 3, 4, 5].reject_values(2, 4) #=> [1, 3, 5]
|
294
|
-
```
|
295
|
-
|
296
288
|
`rposition`
|
297
289
|
------
|
298
290
|
Returns the position of the last matching value.
|
data/docs/HASH.md
CHANGED
@@ -110,7 +110,7 @@ Merge the values of this hash with those from another, setting all values to be
|
|
110
110
|
{ a: 1, b: 2 }.collate(a: 3, b: 4, c: 5) #=> { a: [1, 3], b: [2, 4], c: [5] }
|
111
111
|
```
|
112
112
|
|
113
|
-
`collect_keys`
|
113
|
+
`collect_keys` aka `map_keys`
|
114
114
|
------
|
115
115
|
Returns an array with all keys converted using the block operation.
|
116
116
|
|
@@ -119,7 +119,7 @@ Returns an array with all keys converted using the block operation.
|
|
119
119
|
{ foo: 'bar', 'baz' => :boo }.collect_keys { |k| k.to_s.upcase } #=> ['FOO', BAZ']
|
120
120
|
```
|
121
121
|
|
122
|
-
`collect_values`
|
122
|
+
`collect_values` aka `map_values`
|
123
123
|
------
|
124
124
|
Returns an array with all values converted using the block operation.
|
125
125
|
|
data/docs/NUMERIC.md
CHANGED
@@ -8,16 +8,6 @@ Returns the sum of two numbers.
|
|
8
8
|
4.add(2) #=> 6
|
9
9
|
```
|
10
10
|
|
11
|
-
`clamp`
|
12
|
-
------
|
13
|
-
Returns the closest number outside of the lower and upper bound.
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
1.clamp(3, 6) # => 3
|
17
|
-
5.clamp(3..6) # => 5
|
18
|
-
8.clamp(3, 6) # => 6
|
19
|
-
```
|
20
|
-
|
21
11
|
`close?`
|
22
12
|
------
|
23
13
|
Returns if a number is within the degree of another.
|
data/docs/STRING.md
CHANGED
@@ -511,12 +511,12 @@ If the position is negative, it is counted from the end of the string.
|
|
511
511
|
'example'.to(-2) #=> 'exampl'
|
512
512
|
```
|
513
513
|
|
514
|
-
`
|
514
|
+
`transliterate(!)`
|
515
515
|
------
|
516
516
|
Returns a string with swapped special characters.
|
517
517
|
|
518
518
|
```ruby
|
519
|
-
'źåöé'.
|
519
|
+
'źåöé'.transliterate #=> 'zaoe'
|
520
520
|
```
|
521
521
|
|
522
522
|
`truncate`
|
data/docs/TIME.md
CHANGED
@@ -20,8 +20,8 @@ Converts a `time` object to `strftime` it using a human readable string.
|
|
20
20
|
| --- | --- | --- | --- | --- |
|
21
21
|
| Hour | 24h zero-padded | `h`, `hour`, `hour_padded` | %H | (00..23) |
|
22
22
|
| Hour | 24h blank-padded | `hh`, `HOUR`, `hour_blank` | %k | ( 0..23) |
|
23
|
-
| Hour | 12h zero-padded | `hhh`, `
|
24
|
-
| Hour | 12h blank-padded | `hhhh`, `
|
23
|
+
| Hour | 12h zero-padded | `hhh`, `hour12`, `hour12_padded` | %I | (01..12) |
|
24
|
+
| Hour | 12h blank-padded | `hhhh`, `HOUR12`, `hour12_blank` | %l | ( 1..12) |
|
25
25
|
| Minute | Minute | `n`, `minute` | %M | (00..59) |
|
26
26
|
| Second | Second | `s`, `second` | %S | (00..59) |
|
27
27
|
| Meridian | Lowercase | `ampm`, `meridian` | %P | am..pm |
|
@@ -48,8 +48,8 @@ Converts a `time` object to a predefined format.
|
|
48
48
|
| --- | --- | --- | --- | --- |
|
49
49
|
| Hour | 24h zero-padded | `:hour`, `:hour_padded` | %H | (00..23) |
|
50
50
|
| Hour | 24h blank-padded | `:hour_blank` | %k | ( 0..23) |
|
51
|
-
| Hour | 12h zero-padded | `
|
52
|
-
| Hour | 12h blank-padded | `:
|
51
|
+
| Hour | 12h zero-padded | `hour12`, `:hour12_padded` | %I | (01..12) |
|
52
|
+
| Hour | 12h blank-padded | `:hour12_blank` | %l | ( 1..12) |
|
53
53
|
| Minute | Minute | `:minute` | %M | (00..59) |
|
54
54
|
| Second | Second | `:second` | %S | (00..59) |
|
55
55
|
| Meridian | Lowercase | `:ampm` | %P | am..pm |
|
@@ -67,28 +67,28 @@ Converts a `time` object to a predefined format.
|
|
67
67
|
| Combo | 24h time | `:time_blank` | %k:%M %z | 0:31 |
|
68
68
|
| Combo | 24h time | `:time_tz` | %H:%M %z | 00:31 +0000 |
|
69
69
|
| Combo | 24h time | `:time_tzn` | %H:%M %Z | 00:31 UTC |
|
70
|
-
| Combo | 12h time | `:
|
71
|
-
| Combo | 12h time | `:
|
72
|
-
| Combo | 12h Time | `:
|
73
|
-
| Combo | 12h Time | `:
|
70
|
+
| Combo | 12h time | `:time12`, `:time12_padded` | %I:%M %P | 07:31 am |
|
71
|
+
| Combo | 12h time | `:time12_blank` | %l:%M %P | 7:31 am |
|
72
|
+
| Combo | 12h Time | `:time12_tz` | %I:%M %P %z | 07:31 am +0000 |
|
73
|
+
| Combo | 12h Time | `:time12_tzn` | %I:%M %P %Z | 07:31 am UTC |
|
74
74
|
| Combo | 24h daytime | `:daytime` | %B %-d %H:%M | January 9 00:31 |
|
75
75
|
| Combo | 24h daytime | `:daytime_abbr` | %b %-d %H:%M | Jan 9 00:31 |
|
76
76
|
| Combo | 24h daytime | `:daytime_iso` | %m-%d %H:%M | 01-09 00:31 |
|
77
|
-
| Combo | 12h daytime | `:
|
78
|
-
| Combo | 12h daytime | `:
|
79
|
-
| Combo | 12h daytime | `:
|
77
|
+
| Combo | 12h daytime | `:daytime12` | %B %-d %H:%M | January 9 12:31 am |
|
78
|
+
| Combo | 12h daytime | `:daytime12_abbr` | %b %-d %H:%M | Jan 9 12:31 am |
|
79
|
+
| Combo | 12h daytime | `:daytime12_iso` | %m-%d %H:%M | 01-09 12:31 am |
|
80
80
|
| Combo | 24h datetime | `:datetime` | %B %-d, %Y %H:%M | January 9, 2014 00:31 |
|
81
81
|
| Combo | 24h datetime | `:datetime_abbr` | %b %-d, %Y %H:%M | Jan 9, 2014 00:31 |
|
82
82
|
| Combo | 24h datetime | `:datetime_iso` | %Y-%m-%d %H:%M | 2014-01-09 00:31 |
|
83
83
|
| Combo | 24h datetime | `:datetime_tzn` | %B %-d, %Y %H:%M %Z | January 9, 2014 00:31 UTC |
|
84
84
|
| Combo | 24h datetime | `:datetime_abbr_tzn` | %b %-d, %Y %H:%M %Z | Jan 9, 2014 00:31 UTC |
|
85
85
|
| Combo | 24h datetime | `:datetime_iso_tzn` | %Y-%m-%d %H:%M %z | 2014-01-09 00:31 +0000 |
|
86
|
-
| Combo | 12h datetime | `:
|
87
|
-
| Combo | 12h datetime | `:
|
88
|
-
| Combo | 12h datetime | `:
|
89
|
-
| Combo | 12h datetime | `:
|
90
|
-
| Combo | 12h datetime | `:
|
91
|
-
| Combo | 12h datetime | `:
|
86
|
+
| Combo | 12h datetime | `:datetime12` | %B %-d, %Y %H:%M | January 9, 2014 12:31 am |
|
87
|
+
| Combo | 12h datetime | `:datetime12_abbr` | %b %-d, %Y %H:%M | Jan 9, 2014 12:31 am |
|
88
|
+
| Combo | 12h datetime | `:datetime12_iso` | %Y-%m-%d %H:%M | 2014-01-09 12:31 am |
|
89
|
+
| Combo | 12h datetime | `:datetime12_tzn` | %B %-d, %Y %H:%M %Z | January 9, 2014 12:31 am UTC |
|
90
|
+
| Combo | 12h datetime | `:datetime12_abbr_tzn` | %b %-d, %Y %H:%M %Z | Jan 9, 2014 12:31 am UTC |
|
91
|
+
| Combo | 12h datetime | `:datetime12_iso_tzn` | %Y-%m-%d %H:%M %z | 2014-01-09 12:31 am +0000 |
|
92
92
|
|
93
93
|
```ruby
|
94
94
|
Time.now.stamp(:datetime) #=> 'January 09, 2014 02:31 pm'
|
data/lib/lite/ruby/array.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
if Lite::Ruby.configuration.monkey_patches.include?('array')
|
4
|
+
require 'lite/ruby/safe/array' unless defined?(ActiveSupport)
|
5
|
+
|
4
6
|
class Array
|
5
7
|
|
6
8
|
def assert_min_values!(*valid_values)
|
@@ -109,10 +111,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
109
111
|
# rubocop:enable Metrics/PerceivedComplexity, Style/GuardClause, Style/IfInsideElse
|
110
112
|
# rubocop:enable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
|
111
113
|
|
112
|
-
def deep_dup
|
113
|
-
map(&:deep_dup)
|
114
|
-
end
|
115
|
-
|
116
114
|
def delete_first
|
117
115
|
self[1..-1]
|
118
116
|
end
|
@@ -160,11 +158,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
160
158
|
end
|
161
159
|
|
162
160
|
def except!(*values)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
def from(position)
|
167
|
-
self[position, size] || []
|
161
|
+
reject! { |val| values.include?(val) }
|
162
|
+
self
|
168
163
|
end
|
169
164
|
|
170
165
|
def fulfill(value, amount)
|
@@ -183,54 +178,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
183
178
|
collection << self[-rem, rem]
|
184
179
|
end
|
185
180
|
|
186
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
187
|
-
def in_groups(number, fill_with = nil, &block)
|
188
|
-
collection_size = size
|
189
|
-
division = collection_size.div(number)
|
190
|
-
modulo = collection_size % number
|
191
|
-
|
192
|
-
collection = []
|
193
|
-
start = 0
|
194
|
-
number.times do |int|
|
195
|
-
mod_gt_zero = modulo.positive?
|
196
|
-
grouping = division + (mod_gt_zero && modulo > int ? 1 : 0)
|
197
|
-
collection << last_group = slice(start, grouping)
|
198
|
-
last_group << fill_with if (fill_with != false) && mod_gt_zero && (grouping == division)
|
199
|
-
start += grouping
|
200
|
-
end
|
201
|
-
|
202
|
-
return collection unless defined?(yield)
|
203
|
-
|
204
|
-
collection.each(&block)
|
205
|
-
end
|
206
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
207
|
-
|
208
|
-
# rubocop:disable Metrics/MethodLength, Style/GuardClause
|
209
|
-
def in_groups_of(number, fill_with = nil, &block)
|
210
|
-
if number.to_i <= 0
|
211
|
-
raise ArgumentError, "Group size must be a positive integer, was #{number.inspect}"
|
212
|
-
elsif fill_with == false
|
213
|
-
collection = self
|
214
|
-
else
|
215
|
-
padding = (number - size % number) % number
|
216
|
-
collection = dup.concat(Array.new(padding, fill_with))
|
217
|
-
end
|
218
|
-
|
219
|
-
sliced_collection = collection.each_slice(number)
|
220
|
-
return sliced_collection.to_a unless defined?(yield)
|
221
|
-
|
222
|
-
sliced_collection(&block)
|
223
|
-
end
|
224
|
-
# rubocop:enable Metrics/MethodLength, Style/GuardClause
|
225
|
-
|
226
181
|
def indexes(value)
|
227
182
|
array = []
|
228
183
|
each_with_index { |val, i| array << i if value == val }
|
229
184
|
array
|
230
185
|
end
|
231
186
|
|
232
|
-
alias indices indexes
|
233
|
-
|
234
187
|
def merge(*values)
|
235
188
|
dup.merge!(*values)
|
236
189
|
end
|
@@ -252,7 +205,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
252
205
|
end
|
253
206
|
|
254
207
|
def only!(*values)
|
255
|
-
|
208
|
+
select! { |val| values.include?(val) }
|
209
|
+
self
|
256
210
|
end
|
257
211
|
|
258
212
|
def position(value)
|
@@ -284,7 +238,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
284
238
|
end
|
285
239
|
|
286
240
|
def promote!(value)
|
287
|
-
|
241
|
+
sort_by! { |val| val == value ? -1 : 0 }
|
288
242
|
end
|
289
243
|
|
290
244
|
def rand_sample(max = nil)
|
@@ -292,10 +246,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
292
246
|
sample(amount)
|
293
247
|
end
|
294
248
|
|
295
|
-
def reject_values(*args)
|
296
|
-
reject { |val| args.include?(val) }
|
297
|
-
end
|
298
|
-
|
299
249
|
def rposition(value)
|
300
250
|
idx = rindex(value)
|
301
251
|
return idx if idx.nil?
|
@@ -307,36 +257,13 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
307
257
|
delete_at(Random.rand(size - 1))
|
308
258
|
end
|
309
259
|
|
310
|
-
# rubocop:disable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
|
311
|
-
def split(number = nil)
|
312
|
-
array = [[]]
|
313
|
-
|
314
|
-
if defined?(yield)
|
315
|
-
each { |val| yield(val) ? (array << []) : (array.last << val) }
|
316
|
-
else
|
317
|
-
dup_arr = dup
|
318
|
-
|
319
|
-
until dup_arr.empty?
|
320
|
-
if (idx = dup_arr.index(number))
|
321
|
-
array.last << dup_arr.shift(idx)
|
322
|
-
dup_arr.shift
|
323
|
-
array << []
|
324
|
-
else
|
325
|
-
array.last << arr.shift(dup_arr.size)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
array
|
331
|
-
end
|
332
|
-
# rubocop:enable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
|
333
|
-
|
334
260
|
def strip
|
335
261
|
reject(&:blank?)
|
336
262
|
end
|
337
263
|
|
338
264
|
def strip!
|
339
|
-
|
265
|
+
reject!(&:blank?)
|
266
|
+
self
|
340
267
|
end
|
341
268
|
|
342
269
|
def swap(from, to)
|
@@ -344,24 +271,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
344
271
|
self
|
345
272
|
end
|
346
273
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
def to_sentence(options = {})
|
354
|
-
words_connector = options[:words_connector] || ', '
|
355
|
-
two_words_connector = options[:two_words_connector] || ' and '
|
356
|
-
last_word_connector = options[:last_word_connector] || ', and '
|
357
|
-
|
358
|
-
case size
|
359
|
-
when 0 then ''
|
360
|
-
when 1 then self[0].to_s.dup
|
361
|
-
when 2 then "#{self[0]}#{two_words_connector}#{self[1]}"
|
362
|
-
else "#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}"
|
363
|
-
end
|
364
|
-
end
|
274
|
+
alias extract! except!
|
275
|
+
alias indices indexes
|
276
|
+
alias reject_values except
|
277
|
+
alias reject_values! except!
|
278
|
+
alias select_values only
|
279
|
+
alias select_values! only!
|
365
280
|
|
366
281
|
end
|
367
282
|
end
|