lite-ruby 1.0.1 → 1.0.2

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: ebfe63ca0039bd6f048350883e4561c313c846cdd223bcb1bc08e19d3203c8ff
4
- data.tar.gz: 2b0cec21a13746667b3afaba2936f33928b8d9c368efd13a88312de8c54f2341
3
+ metadata.gz: 19db11fb7da5ef86006b94cc266336955175013164f4f631cf207c607d4286e8
4
+ data.tar.gz: fbe955d7730e10acafb3d288e577e2cfcdf065426543a573fe331427bcb414fc
5
5
  SHA512:
6
- metadata.gz: 26e0c61e5539fd9b9691c62ec69bf942e79f08a2cc3d571a09ad337572c406637098ad0f86b50aaf5a40c138109c1898134c2a206cb09e1039c559a932c97b67
7
- data.tar.gz: 47643cd5b5026e8e8edad9291d4528dc4739ffb1be2406713eb0b384f95e9bf39f0701540b74033067dbf8db77b24e5c02bcae8dbe639c956e77cbcaa35e3528
6
+ metadata.gz: 6af442178978f4528406e0ce3d219157cebbd75a70ca2575dadbf03ae58a87ce71d9e1285127422172e536620fad132951d73cd3b173112563bce7b50a5761c6
7
+ data.tar.gz: 56307ba25fe5b2d7d523ca9b3fba1908ec30443ce25547fcacc28361674f53bd9ef2ef6874957e4932cf66a62b3815e440a3c2f12ba069b42c00830bc67e096b
@@ -30,3 +30,5 @@ Style/Documentation:
30
30
  Enabled: false
31
31
  Style/ExpandPathArguments:
32
32
  Enabled: false
33
+ Style/PerlBackrefs:
34
+ Enabled: false
@@ -6,12 +6,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.2] - 2019-07-21
10
+ ### Added
11
+ - Added Enumerable => `cluster_by`
12
+ - Added Enumerable => `frequency`
13
+ - Added Enumerable => `occur`
14
+ - Added Enumerable => `squeeze`
15
+ - Added Hash => `alias`
16
+ - Added Hash => `collate`
17
+ - Added Hash => `dearray_values`
18
+ - Added Hash => `dearray_singular_values`
19
+ - Added Hash => `delete_unless`
20
+ - Added Hash => `delete_values`
21
+ - Added Hash => `diff`
22
+ - Added Hash => `insert`
23
+ - Added Hash => `invert`
24
+ - Added Hash => `keys?`
25
+ - Added Hash => `only_keys?`
26
+ - Added Hash => `update_each`
27
+ - Added Hash => `update_keys`
28
+ - Added Hash => `update_values`
29
+ - Added Hash => `zip`
30
+ - Added Integer => `bit`
31
+ - Added Integer => `bit?`
32
+ - Added Integer => `bit_clear`
33
+ - Added Integer => `bitmask`
34
+ - Added Integer => `bitmask?`
35
+ - Added Numeric => `at_least?`
36
+ - Added Numeric => `at_most?`
37
+ - Added Numeric => `close?`
38
+ - Added Numeric => `delimit`
39
+ - Added Numeric => `delta`
40
+ - Added Numeric => `range`
41
+ - Added OpenStruct extensions
42
+ - Added String => `ascii_only`
43
+ - Added String => `capitalized?`
44
+ - Added String => `each_word`
45
+ - Added String => `encode_only`
46
+ - Added String => `lchomp`
47
+ - Added String => `methodize`
48
+ - Added String => `modulize`
49
+ - Added String => `pathize`
50
+ - Added String => `quote`
51
+ - Added String => `rotate`
52
+ - Added String => `unquote`
53
+ - Added String => `variablize`
54
+ - Added String => `words`
55
+ - Added String => `words_without_punctuation`
56
+ - Added Struct => `[]`
57
+ - Added Struct => `[]=`
58
+ ### Changed
59
+ - Rename Time => `emperical => imperical`
60
+ - Rename Enumerable => `multiply => produce`
61
+ - Rename Enumerable => `divisible => quotient`
62
+
9
63
  ## [1.0.1] - 2019-07-12
10
64
  ### Added
11
65
  - Added String => `acronym`
12
66
  - Added Struct extensions
13
67
  - Added Time => `elapse`
14
- # Changed
68
+ ### Changed
15
69
  - Configuration
16
70
 
17
71
  ## [1.0.0] - 2019-07-12
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.1)
4
+ lite-ruby (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -38,7 +38,7 @@ Or install it yourself as:
38
38
  ```ruby
39
39
  Lite::Ruby.configure do |config|
40
40
  config.monkey_patches = %w[
41
- array date enumerable hash integer kernel numeric object range string struct time
41
+ array date enumerable hash integer kernel numeric object open_struct range string struct time
42
42
  ]
43
43
  end
44
44
  ```
@@ -53,6 +53,7 @@ end
53
53
  * [Kernel](https://github.com/drexed/lite-ruby/blob/master/docs/KERNEL.md)
54
54
  * [Numeric](https://github.com/drexed/lite-ruby/blob/master/docs/NUMERIC.md)
55
55
  * [Object](https://github.com/drexed/lite-ruby/blob/master/docs/OBJECT.md)
56
+ * [Open Struct](https://github.com/drexed/lite-ruby/blob/master/docs/OPEN_STRUCT.md)
56
57
  * [Range](https://github.com/drexed/lite-ruby/blob/master/docs/RANGE.md)
57
58
  * [String](https://github.com/drexed/lite-ruby/blob/master/docs/STRING.md)
58
59
  * [Struct](https://github.com/drexed/lite-ruby/blob/master/docs/STRUCT.md)
@@ -176,7 +176,7 @@ Converts blank values into `nil`.
176
176
  Generates a hash mapping each unique element in the array to the relative frequency, i.e. the probability, of it appearance.
177
177
 
178
178
  ```ruby
179
- [:a,:b,:c,:c].probability #=> { a: 0.25,b: 0.25,c: 0.5 }
179
+ [:a,:b,:c,:c].probability #=> { a: 0.25, b: 0.25, c: 0.5 }
180
180
  ```
181
181
 
182
182
  `promote(!)`
@@ -5,27 +5,25 @@
5
5
  Groups together adjacent elements into a list of sub-arrays.
6
6
 
7
7
  ```ruby
8
- [2,2,2,3,3,4,2,2,1].cluster { |x| x } #=> [[2,2,2],[3,3],[4],[2,2],[1]]
8
+ [2, 2, 2, 3, 3, 4, 2, 2, 1].cluster { |x| x } #=> [[2, 2, 2], [3, 3], [4], [2, 2], [1]]
9
9
  ```
10
10
 
11
- `deduce`
11
+ `cluster_by`
12
12
  ------
13
- Returns the difference of a collection of numbers.
13
+ Similar to `group_by` but returns an array of the groups.
14
14
 
15
15
  ```ruby
16
- [].deduce #=> 0
17
- [].deduce(nil) #=> nil
18
- [1,2,3].deduce #=> -4
16
+ %w[this is a test].cluster_by { |x| x[0] } #=> [['a'], ['is'], ['this', 'test']]
19
17
  ```
20
18
 
21
- `divisible`
19
+ `deduce`
22
20
  ------
23
- Returns the division of a collection of numbers.
21
+ Returns the difference of a collection of numbers.
24
22
 
25
23
  ```ruby
26
- [].divisible #=> 0
27
- [].divisible(nil) #=> nil
28
- [16,4,2].divisible #=> 2
24
+ [].deduce #=> 0
25
+ [].deduce(nil) #=> nil
26
+ [1,2,3].deduce #=> -4
29
27
  ```
30
28
 
31
29
  `drop_last`
@@ -94,6 +92,14 @@ Returns the exponential of a collection of numbers.
94
92
  [2,3,4].exponential #=> 4096
95
93
  ```
96
94
 
95
+ `frequency` aka `occurrences`
96
+ ------
97
+ Generates a hash mapping each unique symbol in the array to the absolute frequency it appears.
98
+
99
+ ```ruby
100
+ %i[a a b c c c].frequency #=> { a: 2, b: 1, c: 3 }
101
+ ```
102
+
97
103
  `incase?`
98
104
  ------
99
105
  The same as `include?` but tested using `===` instead of `==`.
@@ -123,23 +129,36 @@ Returns if a collection has more than one element while respecting `nil` and `fa
123
129
 
124
130
  ```
125
131
 
126
- `multiple`
132
+ `occur`
133
+ ------
134
+ Returns an array of elements for the elements that occur n times.
135
+
136
+ ```ruby
137
+ a1 = [1, 1, 2, 3, 3, 4, 5, 5]
138
+
139
+ a1.occur(2) #=> [1, 3, 5]
140
+ a1.occur(2..3) #=> [1, 3, 5]
141
+ a1.occur { |n| n > 1 } #=> [1, 3, 5]
142
+ ```
143
+
144
+ `produce`
127
145
  ------
128
146
  Returns the multiplication of a collection of numbers.
129
147
 
130
148
  ```ruby
131
- [].multiple #=> 0
132
- [].multiple(nil) #=> nil
133
- [1,2,3].multiple #=> 6
149
+ [].produce #=> 0
150
+ [].produce(nil) #=> nil
151
+ [1,2,3].produce #=> 6
134
152
  ```
135
153
 
136
- `occurrences`
154
+ `quotient`
137
155
  ------
138
- Returns a hash of the number of times a value appears in an array.
156
+ Returns the division of a collection of numbers.
139
157
 
140
158
  ```ruby
141
- [].occurrences #=> {}
142
- [1,:symbol,'string',3,:symbol,1].occurrences #=> { 1 => 2,:symbol => 2,'string' => 1,3 => 1 }
159
+ [].quotient #=> 0
160
+ [].quotient(nil) #=> nil
161
+ [16,4,2].quotient #=> 2
143
162
  ```
144
163
 
145
164
  `several?`
@@ -153,6 +172,18 @@ Returns if collection has more than one element while not respecting `nil` and `
153
172
  [1,1,3,3].several?(&:even?) #=> false
154
173
  ```
155
174
 
175
+ `squeeze`
176
+ ------
177
+ Squeeze out the same elements.
178
+
179
+ ```ruby
180
+ a1 = [1, 2, 2, 3, 3, 2, 1]
181
+
182
+ a1.squeeze #=> [1, 2, 3, 2, 1]
183
+ a1.sort.squeeze #=> [1, 2, 3]
184
+ a1.squeeze(3) #=> [1, 2, 2, 3, 2, 1]
185
+ ```
186
+
156
187
  `take_last`
157
188
  ------
158
189
  Returns the last number of elements of a collection.
@@ -160,7 +191,7 @@ Returns the last number of elements of a collection.
160
191
  ```ruby
161
192
  [].take_last(1) #=> []
162
193
  [1,2,3].take_last(1) #=> [3]
163
- [1,2,3].take_last(2) #=> [2,3]
194
+ [1,2,3].take_last(2) #=> [2, 3]
164
195
  ```
165
196
 
166
197
  `take_last_if`
@@ -1,5 +1,24 @@
1
1
  # Hash
2
2
 
3
+ `zip`
4
+ ------
5
+ Creates a new hash from two separate arrays.
6
+
7
+ ```ruby
8
+ Hash.zip(%i[a b c], [1, 2, 3]) #=> { a: 1, b: 2, c: 3 }
9
+ ```
10
+
11
+ `alias`
12
+ ------
13
+ Adds a key/value pair from an existing key/value pair.
14
+
15
+ ```ruby
16
+ h1 = { foo: 'bar', baz: 'boo' }
17
+ h1.alias('boo', :foo)
18
+
19
+ h1['boo'] #=> 'bar'
20
+ ```
21
+
3
22
  `assert_valid_keys!`
4
23
  ------
5
24
  Raises an error if key is not included in a list of keys.
@@ -46,6 +65,14 @@ Updates a deeply nested value.
46
65
  { foo: { baz: 'boo' } }.bury(:foo) #=> raises ArgumentError: '2 or more arguments required'
47
66
  ```
48
67
 
68
+ `collate(!)`
69
+ ------
70
+ Merge the values of this hash with those from another, setting all values to be arrays representing the values from both hashes.
71
+
72
+ ```ruby
73
+ { a: 1, b: 2 }.collate(a: 3, b: 4, c: 5) #=> { a: [1, 3], b: [2, 4], c: [5] }
74
+ ```
75
+
49
76
  `collect_keys`
50
77
  ------
51
78
  Returns an array with all keys converted using the block operation.
@@ -64,6 +91,27 @@ Returns an array with all values converted using the block operation.
64
91
  { foo: 'bar', baz: :boo }.collect_values { |k| k.to_s.upcase } #=> ['BAR', BOO']
65
92
  ```
66
93
 
94
+ `dearray_values(!)`
95
+ ------
96
+ Any array values will be replaced with the first element of the array and arrays with no elements will be set to `nil`.
97
+
98
+ ```ruby
99
+ h1 = { a: [1], b: [1, 2], c: 3, d: [] }
100
+
101
+ h1.dearray_values #=> { a: 1, b: 1, c: 3, d: nil }
102
+ h1.dearray_values!(1) #=> { a: 1, b: 2, c: 3, d: nil }
103
+ ```
104
+
105
+ `dearray_singular_values(!)`
106
+ ------
107
+ Any array values with one or no elements will be set to the element or `nil`.
108
+
109
+ ```ruby
110
+ h1 = { a: [1], b: [1, 2], c: 3, d: [] }
111
+
112
+ h1.dearray_singular_values #=> { a: 1, b: [1, 2], c: 3, d: nil }
113
+ ```
114
+
67
115
  `deep_merge(!)`
68
116
  ------
69
117
  Returns a new hash with self and other_hash merged recursively.
@@ -75,6 +123,28 @@ h2 = { a: false, b: { x: [3, 4, 5] } }
75
123
  h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
76
124
  ```
77
125
 
126
+ `delete_unless`
127
+ ------
128
+ Inverse of `delete_if`.
129
+
130
+ ```ruby
131
+ h1 = { a: 1, b: 2, c: 3 }
132
+ h1.delete_unless { |_, v| v == 1 }
133
+
134
+ h1 #=> { a: 1 }
135
+ ```
136
+
137
+ `delete_values`
138
+ ------
139
+ Delete key/value pairs by value.
140
+
141
+ ```ruby
142
+ h1 = { a: 1, b: 2 }
143
+ h1.delete_values(1)
144
+
145
+ h1 #=> { b: 2 }
146
+ ```
147
+
78
148
  `demote(!)`
79
149
  ------
80
150
  Moves a key value pair to the tail of the hash.
@@ -93,6 +163,18 @@ Converts `nil` into a given value.
93
163
  { abc: nil, xyz: 1 }.denillify!(9) #=> { abc: 9, xyz: 1 }
94
164
  ```
95
165
 
166
+ `diff`
167
+ ------
168
+ Difference comparison of two hashes.
169
+
170
+ ```ruby
171
+ h1 = { a: 1, b: 2 }
172
+ h2 = { a: 1, b: 3 }
173
+
174
+ h1.diff(h2) #=> { b: 2 }
175
+ h2.diff(h1) #=> { b: 3 }
176
+ ```
177
+
96
178
  `except(!)`
97
179
  ------
98
180
  Returns a hash that includes everything but the given keys.
@@ -121,6 +203,38 @@ Returns a hash that is transformed in place.
121
203
  { a: 1, b: 2, c: 3 }.hmap { |k, v| { k => v + 3 } } #=> { a: 4, b: 5, c: 6 }
122
204
  ```
123
205
 
206
+ `insert`
207
+ ------
208
+ As with `store` but only if the key isn't already in the hash.
209
+
210
+ ```ruby
211
+ h1 = { a: 1, b: 2 }
212
+
213
+ h1.insert(:c, 3) #=> true
214
+ h1.insert(:b, 3) #=> false
215
+ ```
216
+
217
+ `invert`
218
+ ------
219
+ Create an inverse hash by storing multiple values in arrays.
220
+
221
+ ```ruby
222
+ h1 = { a: 3, b: 3, c: 3, d: 2, e: 9, f: 3, g: 9 }
223
+
224
+ h1.invert #=> { 2 => :d, 3 => %i[f c b a], 9 => %i[g e] }
225
+ ```
226
+
227
+ `keys?` aka `has_keys?`
228
+ ------
229
+ Returns if hash contains the given keys.
230
+
231
+ ```ruby
232
+ h1 = { a: 0, b: 1 }
233
+
234
+ h1.keys?(:a, :b) #=> true
235
+ h1.keys?(:z) #=> false
236
+ ```
237
+
124
238
  `nillify(!)`
125
239
  ------
126
240
  Transforms all blank values to `nil`.
@@ -138,6 +252,17 @@ Returns only key value pairs matching certain keys and any missing one.
138
252
  { :foo => 1, baz: 2 }.only_fill(:foo, :bar, placeholder: 0) #=> { foo: 1, bar: 0 }
139
253
  ```
140
254
 
255
+ `only_keys?` aka `has_only_keys?`
256
+ ------
257
+ Returns if hash contains only the given keys.
258
+
259
+ ```ruby
260
+ h1 = { a: 0, b: 1 }
261
+
262
+ h1.only_keys?(:a, :b) #=> true
263
+ h1.only_keys?(:a) #=> false
264
+ ```
265
+
141
266
  `pair?`
142
267
  ------
143
268
  Returns if the hash has a key with a matching value.
@@ -271,6 +396,30 @@ Converts an object to have an object like API.
271
396
  { foo: { bar: true } }.to_object.foo.bar #=> true
272
397
  ```
273
398
 
399
+ `update_each`
400
+ ------
401
+ Iterate over hash updating the key/value pair.
402
+
403
+ ```ruby
404
+ { a: 1, b: 2 }.update_each { |k, v| { "#{k}!" => v + 1 } } #=> { 'a!' => 2, 'b!' => 3 }
405
+ ```
406
+
407
+ `update_keys`
408
+ ------
409
+ Iterate over hash updating just the keys.
410
+
411
+ ```ruby
412
+ { a: 1, b: 2 }.update_keys { |k| "#{k}!" } #=> { 'a!' => 1, 'b!' => 2 }
413
+ ```
414
+
415
+ `update_values`
416
+ ------
417
+ Iterate over hash updating just the values.
418
+
419
+ ```ruby
420
+ { a: 1, b: 2 }.update_values { |v| v + 1 } #=> { a: 2, b: 3 }
421
+ ```
422
+
274
423
  `vacant?`
275
424
  ------
276
425
  Returns if the value of a key is blank?.
@@ -1,5 +1,50 @@
1
1
  # Integer
2
2
 
3
+ `bit`
4
+ ------
5
+ Calculates the bit of an integer.
6
+
7
+ ```ruby
8
+ 0.bit(4) #=> 16
9
+ 10.bit(-4) #=> 2
10
+ 0b0100.bit(-3) #=> 0
11
+ ```
12
+
13
+ `bit?`
14
+ ------
15
+ Returns if it is a bit set.
16
+
17
+ ```ruby
18
+ 8.bit?(3) #=> true
19
+ 8.bit?(2) #=> false
20
+ ```
21
+
22
+ `bit_clear`
23
+ ------
24
+ Clears a bit.
25
+
26
+ ```ruby
27
+ 4.bit_clear(2) #=> 0
28
+ ```
29
+
30
+ `bitmask`
31
+ ------
32
+ Calculates a bitmask of an integer.
33
+
34
+ ```ruby
35
+ 1.bitmask(6) #=> 7
36
+ 7.bitmask(~2) #=> 5
37
+ ```
38
+
39
+ `bitmask?`
40
+ ------
41
+ Returns if it is a bitmask set.
42
+
43
+ ```ruby
44
+ 8.bitmask?(3) #=> true
45
+ 8.bitmask?(2) #=> false
46
+ ```
47
+
3
48
  `factorial`
4
49
  ------
5
50
  Calculates the factorial of an integer.