lite-ruby 2.0.6 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bfcb5d57c451a25bc72a6ff938450c49d1358a0012f35b5babf3975b8c6f8db
4
- data.tar.gz: 3820932280c726d51defe83da1bf5b359f94233393b6f297bf7ae0a51f1a40df
3
+ metadata.gz: ee69ca4fcfaa7ff5e1af8805fba36795e13bb191ec57c150add24cb26a908cef
4
+ data.tar.gz: dccc37c364c1771639199af8ee5aa838bc03536840f48acbeace3728fdd1fea2
5
5
  SHA512:
6
- metadata.gz: 553e4656191685b19c6c2943833f871a727c913e38ee61a617892e238ca32ca8ffb37547a83e2695f06b13ca8e0ad53de87a6332a9c78f00cbe23469eee6cce5
7
- data.tar.gz: 4eafb5c2e5234393528103f8b2d845ed7f020ed27f99cda57020b6b15ae5f69996aae0377c09fc8acfb0881c0118d46e163872435db8fd210064bf014ad431e3
6
+ metadata.gz: ba4ff364318fc3c9a6f420f063964e31554080b668fbbc4d90eb89d2895644e53f0677e2cbfcd3c1482fbd7b0682f61b586963f585cd90c1eeb0d725dbfa3a69
7
+ data.tar.gz: d530805fba53fe9d2b1ea67f5b81fc003a2e4d85685cfbfe84fd5d0562521970f31632b44d46d4476793ab50e00aab30a98b32c6c5676f4487a190798f2b3a69
data/.rubocop.yml CHANGED
@@ -7,6 +7,8 @@ AllCops:
7
7
  NewCops: enable
8
8
  DisplayCopNames: true
9
9
  DisplayStyleGuide: true
10
+ Gemspec/RequireMFA:
11
+ Enabled: false
10
12
  Gemspec/RequiredRubyVersion:
11
13
  Enabled: false
12
14
  Layout/EmptyLinesAroundBlockBody:
@@ -61,6 +63,8 @@ Style/HashTransformKeys:
61
63
  Enabled: false
62
64
  Style/HashTransformValues:
63
65
  Enabled: false
66
+ Style/OpenStructUse:
67
+ Enabled: false
64
68
  Style/PerlBackrefs:
65
69
  Enabled: false
66
70
  Style/RedundantRegexpCharacterClass:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.3.0] - 2022-02-17
10
+ ### Changed
11
+ - Rename String => `domain` to `uri_domain`
12
+ - Rename String => `fragment` to `uri_fragment`
13
+ - Rename String => `host` to `uri_host`
14
+ - Rename String => `path` to `uri_path`
15
+ - Rename String => `query` to `uri_query`
16
+ - Rename String => `scheme` to `uri_scheme`
17
+
18
+ ## [2.2.0] - 2022-02-17
19
+ ### Added
20
+ - Added Hash => `deep_fetch`
21
+
22
+ ## [2.1.0] - 2022-02-09
23
+ ### Added
24
+ - Added String `domain` to include protocol (more inline with URI method names) [BREAKING]
25
+ - Added String => `fragment`
26
+ - Added String => `host`
27
+ - Added String => `path`
28
+ - Added String => `query`
29
+ - Added String => `scheme
30
+ - Added Date => `day_day` format
31
+ - Added Date => `day_day_abbr` format
32
+ - Added Date => `day_day_iso` format
33
+ - Added Date => `day_date` format
34
+ - Added Date => `day_date_abbr` format
35
+ - Added Date => `day_date_iso` format
36
+ ### Changed
37
+ - Rename String `domain` to `host`
38
+ - String `host` to use URI instead of a regexp
39
+
40
+ ## [2.0.7] - 2021-09-29
41
+ ### Added
42
+ - Added Range => `bounds`
43
+
9
44
  ## [2.0.6] - 2021-09-26
10
45
  ### Changed
11
46
  - Added DateTimeHelper => added missing comma to imperical date
data/Gemfile.lock CHANGED
@@ -1,36 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (2.0.6)
4
+ lite-ruby (2.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.1.4.1)
10
- actionview (= 6.1.4.1)
11
- activesupport (= 6.1.4.1)
12
- rack (~> 2.0, >= 2.0.9)
9
+ actionpack (7.0.2.2)
10
+ actionview (= 7.0.2.2)
11
+ activesupport (= 7.0.2.2)
12
+ rack (~> 2.0, >= 2.2.0)
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.1.4.1)
17
- activesupport (= 6.1.4.1)
16
+ actionview (7.0.2.2)
17
+ activesupport (= 7.0.2.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.1.4.1)
22
+ activesupport (7.0.2.2)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 1.6, < 2)
25
25
  minitest (>= 5.1)
26
26
  tzinfo (~> 2.0)
27
- zeitwerk (~> 2.3)
28
27
  ast (2.4.2)
29
28
  builder (3.2.4)
30
29
  colorize (0.8.1)
31
30
  concurrent-ruby (1.1.9)
32
31
  crass (1.0.6)
33
- diff-lcs (1.4.4)
32
+ diff-lcs (1.5.0)
34
33
  erubi (1.10.0)
35
34
  fasterer (0.9.0)
36
35
  colorize (~> 0.7)
@@ -38,21 +37,21 @@ GEM
38
37
  generator_spec (0.9.4)
39
38
  activesupport (>= 3.0.0)
40
39
  railties (>= 3.0.0)
41
- i18n (1.8.10)
40
+ i18n (1.10.0)
42
41
  concurrent-ruby (~> 1.0)
43
- loofah (2.12.0)
42
+ loofah (2.14.0)
44
43
  crass (~> 1.0.2)
45
44
  nokogiri (>= 1.5.9)
46
45
  method_source (1.0.0)
47
- mini_portile2 (2.6.1)
48
- minitest (5.14.4)
49
- nokogiri (1.12.4)
50
- mini_portile2 (~> 2.6.1)
46
+ mini_portile2 (2.7.1)
47
+ minitest (5.15.0)
48
+ nokogiri (1.13.1)
49
+ mini_portile2 (~> 2.7.0)
51
50
  racc (~> 1.4)
52
51
  parallel (1.21.0)
53
- parser (3.0.2.0)
52
+ parser (3.1.0.0)
54
53
  ast (~> 2.4.1)
55
- racc (1.5.2)
54
+ racc (1.6.0)
56
55
  rack (2.2.3)
57
56
  rack-test (1.1.0)
58
57
  rack (>= 1.0, < 3)
@@ -61,56 +60,57 @@ GEM
61
60
  nokogiri (>= 1.6)
62
61
  rails-html-sanitizer (1.4.2)
63
62
  loofah (~> 2.3)
64
- railties (6.1.4.1)
65
- actionpack (= 6.1.4.1)
66
- activesupport (= 6.1.4.1)
63
+ railties (7.0.2.2)
64
+ actionpack (= 7.0.2.2)
65
+ activesupport (= 7.0.2.2)
67
66
  method_source
68
- rake (>= 0.13)
67
+ rake (>= 12.2)
69
68
  thor (~> 1.0)
70
- rainbow (3.0.0)
69
+ zeitwerk (~> 2.5)
70
+ rainbow (3.1.1)
71
71
  rake (13.0.6)
72
- regexp_parser (2.1.1)
72
+ regexp_parser (2.2.1)
73
73
  rexml (3.2.5)
74
- rspec (3.10.0)
75
- rspec-core (~> 3.10.0)
76
- rspec-expectations (~> 3.10.0)
77
- rspec-mocks (~> 3.10.0)
78
- rspec-core (3.10.1)
79
- rspec-support (~> 3.10.0)
80
- rspec-expectations (3.10.1)
74
+ rspec (3.11.0)
75
+ rspec-core (~> 3.11.0)
76
+ rspec-expectations (~> 3.11.0)
77
+ rspec-mocks (~> 3.11.0)
78
+ rspec-core (3.11.0)
79
+ rspec-support (~> 3.11.0)
80
+ rspec-expectations (3.11.0)
81
81
  diff-lcs (>= 1.2.0, < 2.0)
82
- rspec-support (~> 3.10.0)
83
- rspec-mocks (3.10.2)
82
+ rspec-support (~> 3.11.0)
83
+ rspec-mocks (3.11.0)
84
84
  diff-lcs (>= 1.2.0, < 2.0)
85
- rspec-support (~> 3.10.0)
86
- rspec-support (3.10.2)
87
- rubocop (1.21.0)
85
+ rspec-support (~> 3.11.0)
86
+ rspec-support (3.11.0)
87
+ rubocop (1.25.1)
88
88
  parallel (~> 1.10)
89
- parser (>= 3.0.0.0)
89
+ parser (>= 3.1.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.9.1, < 2.0)
93
+ rubocop-ast (>= 1.15.1, < 2.0)
94
94
  ruby-progressbar (~> 1.7)
95
95
  unicode-display_width (>= 1.4.0, < 3.0)
96
- rubocop-ast (1.11.0)
96
+ rubocop-ast (1.15.2)
97
97
  parser (>= 3.0.1.1)
98
- rubocop-performance (1.11.5)
98
+ rubocop-performance (1.13.2)
99
99
  rubocop (>= 1.7.0, < 2.0)
100
100
  rubocop-ast (>= 0.4.0)
101
101
  rubocop-rake (0.6.0)
102
102
  rubocop (~> 1.0)
103
- rubocop-rspec (2.5.0)
103
+ rubocop-rspec (2.8.0)
104
104
  rubocop (~> 1.19)
105
105
  ruby-progressbar (1.11.0)
106
- ruby_parser (3.17.0)
107
- sexp_processor (~> 4.15, >= 4.15.1)
108
- sexp_processor (4.15.3)
109
- thor (1.1.0)
106
+ ruby_parser (3.18.1)
107
+ sexp_processor (~> 4.16)
108
+ sexp_processor (4.16.0)
109
+ thor (1.2.1)
110
110
  tzinfo (2.0.4)
111
111
  concurrent-ruby (~> 1.0)
112
112
  unicode-display_width (2.1.0)
113
- zeitwerk (2.4.2)
113
+ zeitwerk (2.5.4)
114
114
 
115
115
  PLATFORMS
116
116
  ruby
@@ -128,4 +128,4 @@ DEPENDENCIES
128
128
  rubocop-rspec
129
129
 
130
130
  BUNDLED WITH
131
- 2.2.26
131
+ 2.3.4
data/docs/DATE.md CHANGED
@@ -72,6 +72,12 @@ Converts a `date` object to a predefined format.
72
72
  | Combo | Date | `:date` | %B %-d, %Y | January 9, 2014 |
73
73
  | Combo | Date | `:date_abbr` | %b %-d, %Y | Jan 9, 2014 |
74
74
  | Combo | Date | `:date_iso` | %Y-%m-%d | 2014-01-09 |
75
+ | Combo | Day month day | `:day` | %A, %B %-d | Sunday, January 9 |
76
+ | Combo | Day month day | `:day_abbr` | %a, %b %-d | Sun, Jan 9 |
77
+ | Combo | Day month day | `:day_iso` | %a, %m-%d | Sun, 01-09 |
78
+ | Combo | Day date | `:day_date` | %A, %B %-d, %Y | Sunday, January 9, 2014 |
79
+ | Combo | Day date | `:day_date_abbr` | %a, %b %-d, %Y | Sun, Jan 9, 2014 |
80
+ | Combo | Day date | `:day_date_iso` | %a, %Y-%m-%d | Sun, 2014-01-09 |
75
81
 
76
82
  ```ruby
77
83
  Date.today.to_format(:year) #=> '2014'
data/docs/HASH.md CHANGED
@@ -149,18 +149,20 @@ h1 = { a: [1], b: [1, 2], c: 3, d: [] }
149
149
  h1.dearray_singular_values #=> { a: 1, b: [1, 2], c: 3, d: nil }
150
150
  ```
151
151
 
152
- `deep_merge(!)`
152
+ `deep_fetch`
153
153
  ------
154
- Returns a new hash with self and other_hash merged recursively.
154
+ Returns a nested value if found or raises an error similar to `fetch`.
155
155
 
156
156
  ```ruby
157
157
  h1 = { a: true, b: { c: [1, 2, 3] } }
158
- h2 = { a: false, b: { x: [3, 4, 5] } }
159
158
 
160
- h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
159
+ h1.deep_fetch(:a) #=> true
160
+ h1.deep_fetch(:b, :c) #=> [1, 2, 3]
161
+ h1.deep_fetch(:b, :y) #=> raises KeyError
162
+ h1.deep_fetch(:b, :y) { nil } #=> nil
161
163
  ```
162
164
 
163
- `deep_key`
165
+ `deep_key?`
164
166
  ------
165
167
  Returns if a set of nested keys exists.
166
168
 
@@ -173,6 +175,17 @@ h1.deep_key?(:x) #=> false
173
175
  h1.deep_key?(:a, :c, :x) #=> false
174
176
  ```
175
177
 
178
+ `deep_merge(!)`
179
+ ------
180
+ Returns a new hash with self and other_hash merged recursively.
181
+
182
+ ```ruby
183
+ h1 = { a: true, b: { c: [1, 2, 3] } }
184
+ h2 = { a: false, b: { x: [3, 4, 5] } }
185
+
186
+ h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
187
+ ```
188
+
176
189
  `delete_unless`
177
190
  ------
178
191
  Inverse of `delete_if`.
data/docs/RANGE.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Range
2
2
 
3
+ `bounds`
4
+ ------
5
+ Returns the first and last values of a range.
6
+
7
+ ```ruby
8
+ (1..9).bounds #=> [1, 9]
9
+ ```
10
+
3
11
  `combine`
4
12
  ------
5
13
  Returns two concatenated ranges.
data/docs/STRING.md CHANGED
@@ -108,15 +108,6 @@ Removes the module part from the expression in the string.
108
108
  'String'.demodulize #=> 'String'
109
109
  ```
110
110
 
111
- `domain`
112
- ------
113
- Extracts the domain name from a URL.
114
-
115
- ```ruby
116
- 'http://www.example.com/fake-page'.domain #=> 'www.example.com'
117
- 'example string'.domain #=> 'example string'
118
- ```
119
-
120
111
  `downcase?`
121
112
  ------
122
113
  Returns true if all characters are lowercase.
@@ -597,6 +588,63 @@ Removes any quote types from a given string.
597
588
  '`example`'.unquote #=> 'example'
598
589
  ```
599
590
 
591
+ `uri_domain`
592
+ ------
593
+ Extracts the uri_domain from a URL.
594
+
595
+ ```ruby
596
+ 'http://www.example.com/fake-page'.uri_domain #=> 'http://www.example.com'
597
+ 'www.example.com'.uri_domain #=> nil
598
+ 'example string'.uri_domain #=> nil
599
+ ```
600
+
601
+ `uri_fragment`
602
+ ------
603
+ Extracts the uri_fragment from a URL.
604
+
605
+ ```ruby
606
+ 'http://www.example.com/fake-page?id=30&limit=5#time=1305298413'.uri_fragment #=> 'time=1305298413'
607
+ 'example string'.uri_fragment #=> nil
608
+ ```
609
+
610
+ `uri_host`
611
+ ------
612
+ Extracts the uri_host from a URL.
613
+
614
+ ```ruby
615
+ 'http://www.example.com/fake-page'.uri_host #=> 'www.example.com'
616
+ 'www.example.com'.uri_host #=> nil
617
+ 'example string'.uri_host #=> nil
618
+ ```
619
+
620
+ `uri_path`
621
+ ------
622
+ Extracts the uri_path from a URL.
623
+
624
+ ```ruby
625
+ 'http://www.example.com/fake-page?id=30&limit=5#time=1305298413'.uri_path #=> '/fake-page'
626
+ '/fake-page'.uri_path #=> '/fake-page'
627
+ 'example string'.uri_path #=> nil
628
+ ```
629
+
630
+ `uri_query`
631
+ ------
632
+ Extracts the uri_query from a URL.
633
+
634
+ ```ruby
635
+ 'http://www.example.com/fake-page?id=30&limit=5#time=1305298413'.uri_query #=> 'id=30&limit=5'
636
+ 'example string'.uri_query #=> nil
637
+ ```
638
+
639
+ `uri_scheme`
640
+ ------
641
+ Extracts the uri_scheme from a URL.
642
+
643
+ ```ruby
644
+ 'http://www.example.com/fake-page?id=30&limit=5#time=1305298413'.uri_scheme #=> 'http'
645
+ 'example string'.uri_scheme #=> nil
646
+ ```
647
+
600
648
  `variablize(!)`
601
649
  ------
602
650
  Prepend an "@" to the beginning of a string and replace non-valid characters with underscores.
data/docs/TIME.md CHANGED
@@ -97,6 +97,24 @@ Converts a `time` object to a predefined format.
97
97
  | Combo | 12h datetime | `:datetime12_tzn` | %B %-d, %Y %H:%M %Z | January 9, 2014 12:31 am UTC |
98
98
  | Combo | 12h datetime | `:datetime12_abbr_tzn` | %b %-d, %Y %H:%M %Z | Jan 9, 2014 12:31 am UTC |
99
99
  | Combo | 12h datetime | `:datetime12_iso_tzn` | %Y-%m-%d %H:%M %z | 2014-01-09 12:31 am +0000 |
100
+ | Combo | Day 24h daytime | `:day_daytime` | %B %-d %H:%M | Sunday, January 9 00:31 |
101
+ | Combo | Day 24h daytime | `:day_daytime_abbr` | %b %-d %H:%M | Sun, Jan 9 00:31 |
102
+ | Combo | Day 24h daytime | `:day_daytime_iso` | %m-%d %H:%M | Sun, 01-09 00:31 |
103
+ | Combo | Day 12h daytime | `:day_daytime12` | %B %-d %H:%M | Sunday, January 9 12:31 am |
104
+ | Combo | Day 12h daytime | `:day_daytime12_abbr` | %b %-d %H:%M | Sun, Jan 9 12:31 am |
105
+ | Combo | Day 12h daytime | `:day_daytime12_iso` | %m-%d %H:%M | Sun, 01-09 12:31 am |
106
+ | Combo | Day 24h datetime | `:day_datetime` | %B %-d, %Y %H:%M | Sunday, January 9, 2014 00:31 |
107
+ | Combo | Day 24h datetime | `:day_datetime_abbr` | %b %-d, %Y %H:%M | Sun, Jan 9, 2014 00:31 |
108
+ | Combo | Day 24h datetime | `:day_datetime_iso` | %Y-%m-%d %H:%M | Sun, 2014-01-09 00:31 |
109
+ | Combo | Day 24h datetime | `:day_datetime_tzn` | %B %-d, %Y %H:%M %Z | Sunday, January 9, 2014 00:31 UTC |
110
+ | Combo | Day 24h datetime | `:day_datetime_abbr_tzn` | %b %-d, %Y %H:%M %Z | Sun, Jan 9, 2014 00:31 UTC |
111
+ | Combo | Day 24h datetime | `:day_datetime_iso_tzn` | %Y-%m-%d %H:%M %z | Sun, 2014-01-09 00:31 +0000 |
112
+ | Combo | Day 12h datetime | `:day_datetime12` | %B %-d, %Y %H:%M | Sunday, January 9, 2014 12:31 am |
113
+ | Combo | Day 12h datetime | `:day_datetime12_abbr` | %b %-d, %Y %H:%M | Sun, Jan 9, 2014 12:31 am |
114
+ | Combo | Day 12h datetime | `:day_datetime12_iso` | %Y-%m-%d %H:%M | Sun, 2014-01-09 12:31 am |
115
+ | Combo | Day 12h datetime | `:day_datetime12_tzn` | %B %-d, %Y %H:%M %Z | Sunday, January 9, 2014 12:31 am UTC |
116
+ | Combo | Day 12h datetime | `:day_datetime12_abbr_tzn` | %b %-d, %Y %H:%M %Z | Sun, Jan 9, 2014 12:31 am UTC |
117
+ | Combo | Day 12h datetime | `:day_datetime12_iso_tzn` | %Y-%m-%d %H:%M %z | Sun, 2014-01-09 12:31 am +0000 |
100
118
 
101
119
  ```ruby
102
120
  Time.now.stamp(:datetime) #=> 'January 09, 2014 02:31 pm'
@@ -32,3 +32,9 @@ year_week: '%G-%V'
32
32
  date: '%B %-d, %Y'
33
33
  date_abbr: '%b %-d, %Y'
34
34
  date_iso: '%Y-%m-%d'
35
+ day_day: '%A, %B %-d'
36
+ day_day_abbr: '%a, %b %-d'
37
+ day_day_iso: '%a, %m-%d'
38
+ day_date: '%A, %B %-d, %Y'
39
+ day_date_abbr: '%a, %b %-d, %Y'
40
+ day_date_iso: '%a, %Y-%m-%d'
@@ -40,3 +40,21 @@ datetime_iso_tzn: '%Y-%m-%d %H:%M %z'
40
40
  datetime12_tzn: '%B %-d, %Y %I:%M %P %Z'
41
41
  datetime12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z'
42
42
  datetime12_iso_tzn: '%Y-%m-%d %I:%M %P %z'
43
+ day_daytime: '%A, %B %-d %H:%M'
44
+ day_daytime_abbr: '%a, %b %-d %H:%M'
45
+ day_daytime_iso: '%a, %m-%d %H:%M'
46
+ day_daytime12: '%A, %B %-d %I:%M %P'
47
+ day_daytime12_abbr: '%a, %b %-d %I:%M %P'
48
+ day_daytime12_iso: '%a, %m-%d %I:%M %P'
49
+ day_datetime: '%A, %B %-d, %Y %H:%M'
50
+ day_datetime_abbr: '%a, %b %-d, %Y %H:%M'
51
+ day_datetime_iso: '%a, %Y-%m-%d %H:%M'
52
+ day_datetime12: '%A, %B %-d, %Y %I:%M %P'
53
+ day_datetime12_abbr: '%a, %b %-d, %Y %I:%M %P'
54
+ day_datetime12_iso: '%a, %Y-%m-%d %I:%M %P'
55
+ day_datetime_tzn: '%A, %B %-d, %Y %H:%M %Z'
56
+ day_datetime_abbr_tzn: '%a, %b %-d, %Y %H:%M %Z'
57
+ day_datetime_iso_tzn: '%a, %Y-%m-%d %H:%M %z'
58
+ day_datetime12_tzn: '%A, %B %-d, %Y %I:%M %P %Z'
59
+ day_datetime12_abbr_tzn: '%a, %b %-d, %Y %I:%M %P %Z'
60
+ day_datetime12_iso_tzn: '%a, %Y-%m-%d %I:%M %P %z'
@@ -160,6 +160,10 @@ class Hash
160
160
  replace(dearray_singular_values)
161
161
  end
162
162
 
163
+ def deep_fetch(*keys, &block)
164
+ keys.reduce(self) { |hash_object, key| hash_object.fetch(key, &block) }
165
+ end
166
+
163
167
  def deep_key?(*keys)
164
168
  last_hash = self
165
169
  found_key = false
@@ -48,11 +48,9 @@ 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
52
51
  def factorial
53
52
  (1..self).inject { |acc, i| acc * i } || 0
54
53
  end
55
- # rubocop:enable Lint/AmbiguousRange
56
54
 
57
55
  def factors
58
56
  limit = Math.sqrt(self).floor
@@ -66,7 +66,7 @@ class Numeric
66
66
  end
67
67
 
68
68
  def fraction?
69
- fraction.to_d != 0.0.to_d
69
+ fraction.to_d != BigDecimal('0.0')
70
70
  end
71
71
 
72
72
  def greater_than?(num)
@@ -124,7 +124,7 @@ class Numeric
124
124
  end
125
125
 
126
126
  def one?
127
- to_d == 1.0.to_d
127
+ to_d == BigDecimal('1.0')
128
128
  end
129
129
 
130
130
  def ordinal
@@ -228,11 +228,9 @@ class Numeric
228
228
  "#{pad_precision(options.only(:precision))}#{unit}"
229
229
  end
230
230
 
231
- # rubocop:disable Lint/AmbiguousRange
232
231
  def to_range
233
232
  negative? ? (self..-self) : (-self..self)
234
233
  end
235
- # rubocop:enable Lint/AmbiguousRange
236
234
 
237
235
  def within?(number, epsilon = 0.01)
238
236
  return number == self if epsilon.zero?
@@ -2,6 +2,10 @@
2
2
 
3
3
  class Range
4
4
 
5
+ def bounds
6
+ [self.begin, self.end]
7
+ end
8
+
5
9
  def combine(other)
6
10
  to_a.concat(other.to_a)
7
11
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: false
2
2
 
3
+ require 'uri' unless defined?(URI)
3
4
  require 'yaml' unless defined?(YAML)
4
5
 
5
6
  class String
@@ -53,12 +54,6 @@ class String
53
54
  replace(demodulize)
54
55
  end
55
56
 
56
- def domain
57
- return self unless self =~ %r{^(?:\w+://)?([^/?]+)(?:/|\?|$)}
58
-
59
- Regexp.last_match(1)
60
- end
61
-
62
57
  def downcase?
63
58
  downcase == self
64
59
  end
@@ -408,6 +403,54 @@ class String
408
403
  self
409
404
  end
410
405
 
406
+ def uri_domain
407
+ return if empty?
408
+
409
+ URI.join(self, '/').to_s.chomp('/')
410
+ rescue URI::BadURIError, URI::InvalidURIError
411
+ nil
412
+ end
413
+
414
+ def uri_fragment
415
+ return if empty?
416
+
417
+ URI.parse(self).fragment
418
+ rescue URI::BadURIError, URI::InvalidURIError
419
+ nil
420
+ end
421
+
422
+ def uri_host
423
+ return if empty?
424
+
425
+ URI.parse(self).host
426
+ rescue URI::BadURIError, URI::InvalidURIError
427
+ nil
428
+ end
429
+
430
+ def uri_path
431
+ return if empty?
432
+
433
+ URI.parse(self).path
434
+ rescue URI::BadURIError, URI::InvalidURIError
435
+ nil
436
+ end
437
+
438
+ def uri_query
439
+ return if empty?
440
+
441
+ URI.parse(self).query
442
+ rescue URI::BadURIError, URI::InvalidURIError
443
+ nil
444
+ end
445
+
446
+ def uri_scheme
447
+ return if empty?
448
+
449
+ URI.parse(self).scheme
450
+ rescue URI::BadURIError, URI::InvalidURIError
451
+ nil
452
+ end
453
+
411
454
  def unshift(*patterns)
412
455
  patterns.each_with_object('') { |pat, str| str << pat }
413
456
  .concat(self)
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION = '2.0.6'
6
+ VERSION = '2.3.0'
7
7
 
8
8
  end
9
9
  end
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.6
4
+ version: 2.3.0
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-09-27 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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.26
230
+ rubygems_version: 3.3.4
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Collection of useful Ruby methods for its primitive classes