lite-ruby 2.0.1 → 2.0.5
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/CHANGELOG.md +20 -0
- data/Gemfile.lock +10 -10
- data/README.md +2 -2
- data/docs/DATE.md +1 -1
- data/docs/NUMERIC.md +48 -2
- data/lib/generators/lite/ruby/templates/install.rb +1 -1
- data/lib/lite/ruby/helpers/date_time_helper.rb +2 -2
- data/lib/lite/ruby/integer.rb +2 -0
- data/lib/lite/ruby/{all.rb → monkey_patches.rb} +0 -0
- data/lib/lite/ruby/numeric.rb +19 -0
- data/lib/lite/ruby/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b98854699d757d16a1dedc0d4009fb4db3e3f601510209ff673b0ed59739e17
|
4
|
+
data.tar.gz: 57bf8e45d433913a1768c9804d7e83cf0551da47bb9f4624ece18527f0996b15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc1e2e76116744944340445df23030c2dcccd10467832cf14c6fde912633f2b2dfa9c8b7f8ffef969094f2415388bc6e73e21f9b838c94ed5a2154d1affa9e7
|
7
|
+
data.tar.gz: 2e37a14e882ad5e5ea7636a8d43fa43028b8d633c7f5541321c4a433b2cc369ed42ff24d08f6e11a870d3783ea2eac4fc2a16f2dc646e8660e1cca24ab5a8c7e
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.0.5] - 2021-08-12
|
10
|
+
### Changed
|
11
|
+
- Added DateTimeHelper => remove unit fallback to `stamp`
|
12
|
+
|
13
|
+
## [2.0.4] - 2021-08-12
|
14
|
+
### Changed
|
15
|
+
- Added DateTimeHelper => add unit fallback to `stamp`
|
16
|
+
|
17
|
+
## [2.0.3] - 2021-08-05
|
18
|
+
### Changed
|
19
|
+
- Added Numeric => `negate`
|
20
|
+
- Added Numeric => `many?`
|
21
|
+
- Added Numeric => `one?`
|
22
|
+
- Added Numeric => `none?` to `zero?` alias
|
23
|
+
- Added Numeric => `to_range`
|
24
|
+
|
25
|
+
## [2.0.2] - 2021-07-22
|
26
|
+
### Changed
|
27
|
+
- Changed `all.rb` => `monkey_patches.rb`
|
28
|
+
|
9
29
|
## [2.0.1] - 2021-07-22
|
10
30
|
### Added
|
11
31
|
- Added `all.rb` for monkey patching everything with one command.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (2.0.
|
4
|
+
lite-ruby (2.0.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -40,14 +40,14 @@ GEM
|
|
40
40
|
railties (>= 3.0.0)
|
41
41
|
i18n (1.8.10)
|
42
42
|
concurrent-ruby (~> 1.0)
|
43
|
-
loofah (2.
|
43
|
+
loofah (2.12.0)
|
44
44
|
crass (~> 1.0.2)
|
45
45
|
nokogiri (>= 1.5.9)
|
46
46
|
method_source (1.0.0)
|
47
|
-
mini_portile2 (2.
|
47
|
+
mini_portile2 (2.6.1)
|
48
48
|
minitest (5.14.4)
|
49
|
-
nokogiri (1.
|
50
|
-
mini_portile2 (~> 2.
|
49
|
+
nokogiri (1.12.3)
|
50
|
+
mini_portile2 (~> 2.6.1)
|
51
51
|
racc (~> 1.4)
|
52
52
|
parallel (1.20.1)
|
53
53
|
parser (3.0.2.0)
|
@@ -84,16 +84,16 @@ GEM
|
|
84
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
85
|
rspec-support (~> 3.10.0)
|
86
86
|
rspec-support (3.10.2)
|
87
|
-
rubocop (1.
|
87
|
+
rubocop (1.19.0)
|
88
88
|
parallel (~> 1.10)
|
89
89
|
parser (>= 3.0.0.0)
|
90
90
|
rainbow (>= 2.2.2, < 4.0)
|
91
91
|
regexp_parser (>= 1.8, < 3.0)
|
92
92
|
rexml
|
93
|
-
rubocop-ast (>= 1.
|
93
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
94
94
|
ruby-progressbar (~> 1.7)
|
95
95
|
unicode-display_width (>= 1.4.0, < 3.0)
|
96
|
-
rubocop-ast (1.
|
96
|
+
rubocop-ast (1.10.0)
|
97
97
|
parser (>= 3.0.1.1)
|
98
98
|
rubocop-performance (1.11.4)
|
99
99
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -104,7 +104,7 @@ GEM
|
|
104
104
|
rubocop (~> 1.0)
|
105
105
|
rubocop-ast (>= 1.1.0)
|
106
106
|
ruby-progressbar (1.11.0)
|
107
|
-
ruby_parser (3.
|
107
|
+
ruby_parser (3.17.0)
|
108
108
|
sexp_processor (~> 4.15, >= 4.15.1)
|
109
109
|
sexp_processor (4.15.3)
|
110
110
|
thor (1.1.0)
|
@@ -129,4 +129,4 @@ DEPENDENCIES
|
|
129
129
|
rubocop-rspec
|
130
130
|
|
131
131
|
BUNDLED WITH
|
132
|
-
2.2.
|
132
|
+
2.2.25
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
Any and all monkey patches must be explicitly included anywhere you want to use it.
|
37
37
|
|
38
|
-
To globally use the
|
38
|
+
To globally use the monkey patches, just create an initializer requiring them.
|
39
39
|
|
40
40
|
`rails g lite:ruby:install` will generate the following file:
|
41
41
|
`../config/initalizers/lite_ruby.rb`
|
@@ -45,7 +45,7 @@ They can be disabled by commenting any of them out.
|
|
45
45
|
```ruby
|
46
46
|
# frozen_string_literal: true
|
47
47
|
|
48
|
-
require 'lite/ruby/
|
48
|
+
require 'lite/ruby/monkey_patches'
|
49
49
|
|
50
50
|
# - or -
|
51
51
|
|
data/docs/DATE.md
CHANGED
@@ -37,7 +37,7 @@ Converts a `date` object to a predefined format.
|
|
37
37
|
|
38
38
|
| Directive | Type | Key | `strftime` | Result |
|
39
39
|
| --- | --- | --- | --- | --- |
|
40
|
-
| Weekday | Zero-padded |
|
40
|
+
| Weekday | Zero-padded | `:weekday`, `:weekday_padded` | %d | (01..31) |
|
41
41
|
| Weekday | Blank-padded | `:weekday_blank` | %_d | ( 1..31) |
|
42
42
|
| Weekday | Unpadded | `:weekday_unpadded` | %-d | (1..31) |
|
43
43
|
| Weekday | Name | `:weekday_name` | %A | Sunday |
|
data/docs/NUMERIC.md
CHANGED
@@ -149,6 +149,15 @@ Returns if self is less than or equal to n.
|
|
149
149
|
3.less_than_or_equal_to?(4) #=> true
|
150
150
|
```
|
151
151
|
|
152
|
+
`many?`
|
153
|
+
------
|
154
|
+
Returns if a number is greater than one.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
4.many? #=> true
|
158
|
+
1.many? #=> false
|
159
|
+
```
|
160
|
+
|
152
161
|
`markdown_percentage`
|
153
162
|
------
|
154
163
|
Returns the difference of a number and a percentage of it.
|
@@ -182,6 +191,24 @@ Returns if a number can be evenly divided by n.
|
|
182
191
|
7.multiple_of?(3) #=> false
|
183
192
|
```
|
184
193
|
|
194
|
+
`negate`
|
195
|
+
------
|
196
|
+
Returns the negation of a number.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
4.negate #=> -4
|
200
|
+
-2.negate #=> 2
|
201
|
+
```
|
202
|
+
|
203
|
+
`none?` aka `zero?`
|
204
|
+
------
|
205
|
+
Returns if a number is to zero.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
0.none? #=> true
|
209
|
+
1.none? #=> false
|
210
|
+
```
|
211
|
+
|
185
212
|
`not_equal_to?` aka `not_eq?` aka `inequal_to?` aka `ineq?`
|
186
213
|
------
|
187
214
|
Returns if not matching equality using `!=`.
|
@@ -191,6 +218,16 @@ Returns if not matching equality using `!=`.
|
|
191
218
|
3.not_equal_to?(3) #=> false
|
192
219
|
```
|
193
220
|
|
221
|
+
`one?`
|
222
|
+
------
|
223
|
+
Returns if a number is equal to one.
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
1.one? #=> true
|
227
|
+
1.0.one? #=> true
|
228
|
+
4.one? #=> false
|
229
|
+
```
|
230
|
+
|
194
231
|
`ordinal`
|
195
232
|
------
|
196
233
|
Returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
@@ -317,15 +354,24 @@ unit | string | '$'
|
|
317
354
|
3.to_currency(unit: '@') #=> '@3.00'
|
318
355
|
```
|
319
356
|
|
320
|
-
`
|
357
|
+
`to_nearest_value`
|
321
358
|
------
|
322
|
-
|
359
|
+
Returns the value in values that is nearest to the number.
|
323
360
|
|
324
361
|
```ruby
|
325
362
|
5.to_nearest_value([1, 3, 6, 9]) #=> 6
|
326
363
|
3.5.to_nearest_value([3.0, 3.3, 3.6, 3.9]) #=> 3.6
|
327
364
|
```
|
328
365
|
|
366
|
+
`to_range`
|
367
|
+
------
|
368
|
+
Returns a range of a number from negative to positive.
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
5.to_range #=> -5..5
|
372
|
+
-5.to_range #=> -5..5
|
373
|
+
```
|
374
|
+
|
329
375
|
`to_percentage`
|
330
376
|
------
|
331
377
|
Converts a number to percentage string.
|
data/lib/lite/ruby/integer.rb
CHANGED
@@ -48,9 +48,11 @@ class Integer
|
|
48
48
|
(0...num).inject(1) { |acc, i| (acc * (self - i)) / (i + 1) }
|
49
49
|
end
|
50
50
|
|
51
|
+
# rubocop:disable Lint/AmbiguousRange
|
51
52
|
def factorial
|
52
53
|
(1..self).inject { |acc, i| acc * i } || 0
|
53
54
|
end
|
55
|
+
# rubocop:enable Lint/AmbiguousRange
|
54
56
|
|
55
57
|
def factors
|
56
58
|
limit = Math.sqrt(self).floor
|
File without changes
|
data/lib/lite/ruby/numeric.rb
CHANGED
@@ -93,6 +93,10 @@ class Numeric
|
|
93
93
|
num >= self
|
94
94
|
end
|
95
95
|
|
96
|
+
def many?
|
97
|
+
to_f > 1.0
|
98
|
+
end
|
99
|
+
|
96
100
|
def markdown_percentage(percent)
|
97
101
|
to_f * ((100.0 - percent.to_f) / 100.0)
|
98
102
|
end
|
@@ -111,10 +115,18 @@ class Numeric
|
|
111
115
|
modulo(number).zero?
|
112
116
|
end
|
113
117
|
|
118
|
+
def negate
|
119
|
+
-self
|
120
|
+
end
|
121
|
+
|
114
122
|
def not_equal_to?(num)
|
115
123
|
self != num
|
116
124
|
end
|
117
125
|
|
126
|
+
def one?
|
127
|
+
to_d == 1.0.to_d
|
128
|
+
end
|
129
|
+
|
118
130
|
def ordinal
|
119
131
|
return 'th' if (11..13).cover?(abs % 100)
|
120
132
|
|
@@ -216,6 +228,12 @@ class Numeric
|
|
216
228
|
"#{pad_precision(options.only(:precision))}#{unit}"
|
217
229
|
end
|
218
230
|
|
231
|
+
# rubocop:disable Lint/AmbiguousRange
|
232
|
+
def to_range
|
233
|
+
negative? ? (self..-self) : (-self..self)
|
234
|
+
end
|
235
|
+
# rubocop:enable Lint/AmbiguousRange
|
236
|
+
|
219
237
|
def within?(number, epsilon = 0.01)
|
220
238
|
return number == self if epsilon.zero?
|
221
239
|
|
@@ -236,6 +254,7 @@ class Numeric
|
|
236
254
|
alias ineq? not_equal_to?
|
237
255
|
alias lt? less_than?
|
238
256
|
alias lteq? less_than_or_equal_to?
|
257
|
+
alias none? zero?
|
239
258
|
alias not_eq? not_equal_to?
|
240
259
|
alias plus_minus range
|
241
260
|
|
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: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -178,7 +178,6 @@ files:
|
|
178
178
|
- lib/generators/lite/ruby/templates/install.rb
|
179
179
|
- lib/lite/.DS_Store
|
180
180
|
- lib/lite/ruby.rb
|
181
|
-
- lib/lite/ruby/all.rb
|
182
181
|
- lib/lite/ruby/array.rb
|
183
182
|
- lib/lite/ruby/boolean.rb
|
184
183
|
- lib/lite/ruby/date.rb
|
@@ -193,6 +192,7 @@ files:
|
|
193
192
|
- lib/lite/ruby/helpers/date_time_helper.rb
|
194
193
|
- lib/lite/ruby/integer.rb
|
195
194
|
- lib/lite/ruby/kernel.rb
|
195
|
+
- lib/lite/ruby/monkey_patches.rb
|
196
196
|
- lib/lite/ruby/numeric.rb
|
197
197
|
- lib/lite/ruby/object.rb
|
198
198
|
- lib/lite/ruby/open_struct.rb
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
|
-
rubygems_version: 3.2.
|
230
|
+
rubygems_version: 3.2.25
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: Collection of useful Ruby methods for its primitive classes
|