lite-ruby 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +4 -4
- data/README.md +4 -1
- data/docs/BOOLEAN.md +19 -0
- data/docs/NUMERIC.md +16 -0
- data/docs/OBJECT.md +22 -3
- data/docs/STRING.md +9 -0
- data/lib/generators/lite/ruby/templates/install.rb +2 -1
- data/lib/lite/ruby/boolean.rb +29 -0
- data/lib/lite/ruby/configuration.rb +2 -2
- data/lib/lite/ruby/numeric.rb +8 -0
- data/lib/lite/ruby/object.rb +23 -23
- data/lib/lite/ruby/string.rb +9 -0
- data/lib/lite/ruby/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04000606ae7be2f1ccd5eabce5505152245c7d887831b1cf5d8b4fb314eaa493
|
4
|
+
data.tar.gz: 6475eda4f943b7eb690b94712fad42ed0ed56801750c3806a31fcb71b3c7c509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01b1a425b1b5e7c9c821dade32a826c2b655028c32bd70a149a573d113d509a36ffb168ed0e9a30e088611bd3cf4bd255c7d5c7294f05fb310d84b89e298407a
|
7
|
+
data.tar.gz: 8707863ed5227904179e70b77996a31680f18d8a12e86893ed9c0e492165905deeaead2f5c2477c9ff77151f73188513cd69ad21aacaaaad5a1f2956a679c444
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.4] - 2019-08-09
|
10
|
+
### Added
|
11
|
+
- Added more boolean value checks
|
12
|
+
- Added Numeric => `markdown_percentage`
|
13
|
+
- Added Numeric => `markup_percentage`
|
14
|
+
- Added Object => `is_any?`
|
15
|
+
- Added Object => `to_bool`
|
16
|
+
- Added String => `dedupe`
|
17
|
+
### Changed
|
18
|
+
- Move boolean classes to its own file
|
19
|
+
|
9
20
|
## [1.0.3] - 2019-07-30
|
10
21
|
### Added
|
11
22
|
- Added String => `non_possessive`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (1.0.
|
4
|
+
lite-ruby (1.0.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -57,7 +57,7 @@ GEM
|
|
57
57
|
rails-dom-testing (2.0.3)
|
58
58
|
activesupport (>= 4.2.0)
|
59
59
|
nokogiri (>= 1.6)
|
60
|
-
rails-html-sanitizer (1.0
|
60
|
+
rails-html-sanitizer (1.2.0)
|
61
61
|
loofah (~> 2.2, >= 2.2.2)
|
62
62
|
railties (5.2.3)
|
63
63
|
actionpack (= 5.2.3)
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
81
|
rspec-support (~> 3.8.0)
|
82
82
|
rspec-support (3.8.2)
|
83
|
-
rubocop (0.
|
83
|
+
rubocop (0.74.0)
|
84
84
|
jaro_winkler (~> 1.5.1)
|
85
85
|
parallel (~> 1.10)
|
86
86
|
parser (>= 2.6)
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
unicode-display_width (>= 1.4.0, < 1.7)
|
90
90
|
rubocop-performance (1.4.1)
|
91
91
|
rubocop (>= 0.71.0)
|
92
|
-
rubocop-rspec (1.
|
92
|
+
rubocop-rspec (1.35.0)
|
93
93
|
rubocop (>= 0.60.0)
|
94
94
|
ruby-progressbar (1.10.1)
|
95
95
|
ruby_parser (3.13.1)
|
data/README.md
CHANGED
@@ -38,7 +38,8 @@ 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 open_struct range string
|
41
|
+
array boolean date enumerable hash integer kernel numeric object open_struct range string
|
42
|
+
struct time
|
42
43
|
]
|
43
44
|
end
|
44
45
|
```
|
@@ -46,6 +47,7 @@ end
|
|
46
47
|
## Extensions
|
47
48
|
|
48
49
|
* [Array](https://github.com/drexed/lite-ruby/blob/master/docs/ARRAY.md)
|
50
|
+
* [Boolean](https://github.com/drexed/lite-ruby/blob/master/docs/BOOLEAN.md)
|
49
51
|
* [Date](https://github.com/drexed/lite-ruby/blob/master/docs/DATE.md)
|
50
52
|
* [Enumerable](https://github.com/drexed/lite-ruby/blob/master/docs/ENUMERABLE.md)
|
51
53
|
* [Hash](https://github.com/drexed/lite-ruby/blob/master/docs/HASH.md)
|
@@ -66,6 +68,7 @@ The following are highly recommended 3rd-party extensions to supplement your wor
|
|
66
68
|
* **Performance:** Escape Utils - https://github.com/brianmario/escape_utils
|
67
69
|
* **Performance:** Fast Blank - https://github.com/SamSaffron/fast_blank
|
68
70
|
* **Extensions:** Facets - https://github.com/rubyworks/facets
|
71
|
+
* **Extensions:** Finishing Moves - https://github.com/forgecrafted/finishing_moves
|
69
72
|
|
70
73
|
## Port
|
71
74
|
|
data/docs/BOOLEAN.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Boolean
|
2
|
+
|
3
|
+
`to_bool` aka `to_b`
|
4
|
+
------
|
5
|
+
Returns self.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
true.to_bool #=> true
|
9
|
+
false.to_b #=> false
|
10
|
+
```
|
11
|
+
|
12
|
+
`to_i`
|
13
|
+
------
|
14
|
+
Returns the integer representation of a boolean.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
true.to_i #=> 1
|
18
|
+
false.to_i #=> 0
|
19
|
+
```
|
data/docs/NUMERIC.md
CHANGED
@@ -159,6 +159,22 @@ Returns if self is less than or equal to n.
|
|
159
159
|
3.less_than_or_equal_to?(4) #=> true
|
160
160
|
```
|
161
161
|
|
162
|
+
`markdown_percentage`
|
163
|
+
------
|
164
|
+
Returns the difference of a number and a percentage of it.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
4.markdown_percentage(25) #=> 3
|
168
|
+
```
|
169
|
+
|
170
|
+
`markup_percentage`
|
171
|
+
------
|
172
|
+
Returns the sum of a number and a percentage of it.
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
4.markup_percentage(25) #=> 5
|
176
|
+
```
|
177
|
+
|
162
178
|
`multiply`
|
163
179
|
------
|
164
180
|
Returns the multiplication of two numbers.
|
data/docs/OBJECT.md
CHANGED
@@ -59,7 +59,7 @@ true.false? #=> false
|
|
59
59
|
|
60
60
|
`falsey?`
|
61
61
|
------
|
62
|
-
Returns if an object is `false
|
62
|
+
Returns if an object is `0 f false n no off`.
|
63
63
|
|
64
64
|
```ruby
|
65
65
|
false.falsey? #=> true
|
@@ -87,13 +87,22 @@ Returns if an object is a `hash`.
|
|
87
87
|
|
88
88
|
`integer?`
|
89
89
|
------
|
90
|
-
Returns if an object is
|
90
|
+
Returns if an object is an `integer`.
|
91
91
|
|
92
92
|
```ruby
|
93
93
|
1.integer? #=> true
|
94
94
|
1.0.integer? #=> false
|
95
95
|
```
|
96
96
|
|
97
|
+
`is_any?`
|
98
|
+
------
|
99
|
+
Returns if an object is of any class type supplied.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
1.is_any?(String, Integer) #=> true
|
103
|
+
0.is_any?(String, Symbol) #=> false
|
104
|
+
```
|
105
|
+
|
97
106
|
`numeric?`
|
98
107
|
------
|
99
108
|
Returns if an object is `numeric`.
|
@@ -270,6 +279,16 @@ Time.now.time? #=> true
|
|
270
279
|
'foo'.time? #=> false
|
271
280
|
```
|
272
281
|
|
282
|
+
`to_bool` aka `to_b`
|
283
|
+
------
|
284
|
+
Returns a `true` or `false` value if it can be converted to a boolean, else nil.
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
true.to_bool #=> true
|
288
|
+
'0'.to_bool #=> false
|
289
|
+
'A'.to_bool #=> nil
|
290
|
+
```
|
291
|
+
|
273
292
|
`true?`
|
274
293
|
------
|
275
294
|
Returns if an object is `true`.
|
@@ -281,7 +300,7 @@ false.true? #=> false
|
|
281
300
|
|
282
301
|
`truthy?`
|
283
302
|
------
|
284
|
-
Returns if an object is `true
|
303
|
+
Returns if an object is `1 t true y yes on`.
|
285
304
|
|
286
305
|
```ruby
|
287
306
|
true.truthy? #=> true
|
data/docs/STRING.md
CHANGED
@@ -99,6 +99,15 @@ Removes the rightmost segment from the constant expression in the string.
|
|
99
99
|
''.deconstantize # => ''
|
100
100
|
```
|
101
101
|
|
102
|
+
`dedupe(!)`
|
103
|
+
------
|
104
|
+
Removes multiple concurrent occurrences of a character and reduce them to a single occurrence.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
'/foo//bar////baz/bing'.dedupe('/') #=> '/foo/bar/baz/bing'
|
108
|
+
'foo___bar_baz---bing'.dedupe!('-_') #=> 'foo_bar_baz-bing'
|
109
|
+
```
|
110
|
+
|
102
111
|
`demodulize(!)`
|
103
112
|
------
|
104
113
|
Removes the module part from the expression in the string.
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Lite::Ruby.configure do |config|
|
4
4
|
config.monkey_patches = %w[
|
5
|
-
array date enumerable hash integer kernel numeric object open_struct range string
|
5
|
+
array boolean date enumerable hash integer kernel numeric object open_struct range string
|
6
|
+
struct time
|
6
7
|
]
|
7
8
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FalseClass
|
4
|
+
|
5
|
+
def to_bool
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
alias to_b to_bool
|
10
|
+
|
11
|
+
def to_i
|
12
|
+
0
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class TrueClass
|
18
|
+
|
19
|
+
def to_bool
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
alias to_b to_bool
|
24
|
+
|
25
|
+
def to_i
|
26
|
+
1
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -9,8 +9,8 @@ module Lite
|
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@monkey_patches = %w[
|
12
|
-
array date enumerable hash integer kernel numeric object open_struct range string
|
13
|
-
time
|
12
|
+
array boolean date enumerable hash integer kernel numeric object open_struct range string
|
13
|
+
struct time
|
14
14
|
]
|
15
15
|
end
|
16
16
|
|
data/lib/lite/ruby/numeric.rb
CHANGED
@@ -120,6 +120,14 @@ class Numeric
|
|
120
120
|
|
121
121
|
alias lteq? less_than_or_equal_to?
|
122
122
|
|
123
|
+
def markdown_percentage(percent)
|
124
|
+
to_f * ((100.0 - percent.to_f) / 100.0)
|
125
|
+
end
|
126
|
+
|
127
|
+
def markup_percentage(percent)
|
128
|
+
to_f + (to_f * (percent.to_f / 100.0))
|
129
|
+
end
|
130
|
+
|
123
131
|
def multiply(num)
|
124
132
|
self * num
|
125
133
|
end
|
data/lib/lite/ruby/object.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
class Object
|
4
4
|
|
5
|
-
FALSE_VALUES ||= [
|
6
|
-
|
5
|
+
FALSE_VALUES ||= %w[
|
6
|
+
0 f false n no off
|
7
7
|
].freeze
|
8
|
-
TRUE_VALUES ||= [
|
9
|
-
|
8
|
+
TRUE_VALUES ||= %w[
|
9
|
+
1 t true y yes on
|
10
10
|
].freeze
|
11
11
|
|
12
12
|
def array?
|
@@ -26,7 +26,8 @@ class Object
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def boolean?
|
29
|
-
|
29
|
+
val = to_s.downcase
|
30
|
+
TRUE_VALUES.include?(val) || FALSE_VALUES.include?(val)
|
30
31
|
end
|
31
32
|
|
32
33
|
def date?
|
@@ -40,7 +41,7 @@ class Object
|
|
40
41
|
# rubocop:enable Style/YodaCondition
|
41
42
|
|
42
43
|
def falsey?
|
43
|
-
nil? || FALSE_VALUES.include?(
|
44
|
+
nil? || FALSE_VALUES.include?(to_s.downcase)
|
44
45
|
end
|
45
46
|
|
46
47
|
def float?
|
@@ -55,6 +56,12 @@ class Object
|
|
55
56
|
is_a?(Integer)
|
56
57
|
end
|
57
58
|
|
59
|
+
# rubocop:disable Naming/PredicateName
|
60
|
+
def is_any?(*objs)
|
61
|
+
objs.any? { |obj| is_a?(obj) }
|
62
|
+
end
|
63
|
+
# rubocop:enable Naming/PredicateName
|
64
|
+
|
58
65
|
def numeral?
|
59
66
|
!to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
|
60
67
|
end
|
@@ -129,6 +136,15 @@ class Object
|
|
129
136
|
is_a?(Time)
|
130
137
|
end
|
131
138
|
|
139
|
+
def to_bool
|
140
|
+
return true if truthy?
|
141
|
+
return false if falsey?
|
142
|
+
|
143
|
+
nil
|
144
|
+
end
|
145
|
+
|
146
|
+
alias to_b to_bool
|
147
|
+
|
132
148
|
# rubocop:disable Style/YodaCondition
|
133
149
|
def true?
|
134
150
|
true == self
|
@@ -136,7 +152,7 @@ class Object
|
|
136
152
|
# rubocop:enable Style/YodaCondition
|
137
153
|
|
138
154
|
def truthy?
|
139
|
-
TRUE_VALUES.include?(
|
155
|
+
TRUE_VALUES.include?(to_s.downcase)
|
140
156
|
end
|
141
157
|
|
142
158
|
def try(*obj, &block)
|
@@ -164,19 +180,3 @@ class Object
|
|
164
180
|
end
|
165
181
|
|
166
182
|
end
|
167
|
-
|
168
|
-
class FalseClass
|
169
|
-
|
170
|
-
def to_i
|
171
|
-
0
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
class TrueClass
|
177
|
-
|
178
|
-
def to_i
|
179
|
-
1
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
data/lib/lite/ruby/string.rb
CHANGED
@@ -104,6 +104,15 @@ class String
|
|
104
104
|
replace(deconstantize)
|
105
105
|
end
|
106
106
|
|
107
|
+
def dedupe(pattern)
|
108
|
+
dup.dedupe!(pattern)
|
109
|
+
end
|
110
|
+
|
111
|
+
def dedupe!(pattern)
|
112
|
+
pattern.each_char { |char| gsub!(/#{Regexp.escape(char)}{2,}/, char) }
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
107
116
|
def demodulize
|
108
117
|
gsub(/^.*::/, '')
|
109
118
|
end
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- bin/console
|
146
146
|
- bin/setup
|
147
147
|
- docs/ARRAY.md
|
148
|
+
- docs/BOOLEAN.md
|
148
149
|
- docs/DATE.md
|
149
150
|
- docs/ENUMERABLE.md
|
150
151
|
- docs/HASH.md
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/generators/lite/ruby/templates/install.rb
|
162
163
|
- lib/lite/ruby.rb
|
163
164
|
- lib/lite/ruby/array.rb
|
165
|
+
- lib/lite/ruby/boolean.rb
|
164
166
|
- lib/lite/ruby/configuration.rb
|
165
167
|
- lib/lite/ruby/date.rb
|
166
168
|
- lib/lite/ruby/enumerable.rb
|