crystal_goodies 1.0.0 → 1.0.1
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 +4 -0
- data/README.md +3 -1
- data/lib/crystal_goodies/enumerable.rb +0 -1
- data/lib/crystal_goodies/string.rb +5 -74
- data/lib/crystal_goodies/version.rb +1 -1
- data/sig/enumerable.rbs +1 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4b7ae551c485c71237af166ebd2290d65f1f2773aba36879c7f8ea26cdf2146
|
4
|
+
data.tar.gz: 10760bdbd7c24e1eb6f7fed9a44179fd747487e8962730f34f1afe8c12e2ec25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da29836bb1d4979e3f1e57d83c4c9c00297fcba47bd5160ebf987cc0ed29178ad0da84048bc504a169c2d6d737ce5bd93d5ca7a2c8e1276da522e342fc2627a0
|
7
|
+
data.tar.gz: 1658a8a130350d2cd70cffff5924f7a7ec122f238ec055601e1dacb3ca551e8367bf19319172bde7d4b8b9ba851928afdece04063060ce0ccde5ee1214a04a4f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## 💡 About
|
4
4
|
|
5
|
-
Class's methods port from Crystal.
|
5
|
+
Class's methods inspired/port from Crystal.
|
6
6
|
|
7
7
|
## 📥 Installation
|
8
8
|
|
@@ -25,10 +25,12 @@ In Ruby do:
|
|
25
25
|
```rb
|
26
26
|
require 'crystal_goodies'
|
27
27
|
```
|
28
|
+
|
28
29
|
TODO
|
29
30
|
|
30
31
|
## 💌 Credits
|
31
32
|
|
32
33
|
- [**Crystal**](https://crystal-lang.org) by [it's contributors](https://github.com/crystal-lang/crystal/graphs/contributors)
|
34
|
+
- [**Ruby on Rails**](https://rubyonrails.org) by [it's contributors](https://github.com/rails/rails/graphs/contributors)
|
33
35
|
|
34
36
|
<a href="https://codeberg.org/NNB"><img width="100%" src="https://capsule-render.vercel.app/api?type=waving§ion=footer&color=DC2626&fontColor=FEF2F2&height=128&desc=Made%20with%20%26lt;3%20by%20NNB&descAlignY=80" /></a>
|
@@ -61,78 +61,9 @@ module CrystalGoodies
|
|
61
61
|
# "3.14IsPi".underscore # => "3.14_is_pi"
|
62
62
|
# ```
|
63
63
|
def underscore(*options)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
first = true
|
68
|
-
last_is_downcase = false
|
69
|
-
last_is_upcase = false
|
70
|
-
last_is_digit = false
|
71
|
-
mem = nil
|
72
|
-
|
73
|
-
each_char do |char|
|
74
|
-
if options.ascii?
|
75
|
-
digit = char.ascii_number?
|
76
|
-
downcase = digit || char.ascii_lowercase?
|
77
|
-
upcase = char.ascii_uppercase?
|
78
|
-
else
|
79
|
-
digit = char.number?
|
80
|
-
downcase = digit || char.lowercase?
|
81
|
-
upcase = char.uppercase?
|
82
|
-
end
|
83
|
-
|
84
|
-
if first
|
85
|
-
char.downcase(options) { |c| string << c }
|
86
|
-
elsif last_is_downcase && upcase
|
87
|
-
if mem
|
88
|
-
# This is the case of A1Bcd, we need to put 'mem' (not to need to convert as downcase
|
89
|
-
# ^
|
90
|
-
# because 'mem' is digit surely) before putting this char as downcase.
|
91
|
-
string << mem
|
92
|
-
mem = nil
|
93
|
-
end
|
94
|
-
# This is the case of AbcDe, we need to put an underscore before the 'D'
|
95
|
-
# ^
|
96
|
-
string << '_'
|
97
|
-
char.downcase(options) { |c| string << c }
|
98
|
-
elsif (last_is_upcase || last_is_digit) && (upcase || digit)
|
99
|
-
# This is the case of 1) A1Bcd, 2) A1BCd or 3) A1B_cd:if the next char is upcase (case 1) we need
|
100
|
-
# ^ ^ ^
|
101
|
-
# 1) we need to append this char as downcase
|
102
|
-
# 2) we need to append an underscore and then the char as downcase, so we save this char
|
103
|
-
# in 'mem' and decide later
|
104
|
-
# 3) we need to append this char as downcase and then a single underscore
|
105
|
-
if mem
|
106
|
-
# case 2
|
107
|
-
mem.downcase(options) { |c| string << c }
|
108
|
-
end
|
109
|
-
mem = char
|
110
|
-
else
|
111
|
-
if mem
|
112
|
-
if char == '_'
|
113
|
-
# case 3
|
114
|
-
elsif last_is_upcase && downcase
|
115
|
-
# case 1
|
116
|
-
string << '_'
|
117
|
-
end
|
118
|
-
mem.downcase(options) { |c| string << c }
|
119
|
-
mem = nil
|
120
|
-
end
|
121
|
-
|
122
|
-
char.downcase(options) { |c| string << c }
|
123
|
-
end
|
124
|
-
|
125
|
-
last_is_downcase = downcase
|
126
|
-
last_is_upcase = upcase
|
127
|
-
last_is_digit = digit
|
128
|
-
first = false
|
129
|
-
end
|
130
|
-
|
131
|
-
mem&.downcase(options) { |c| string << c }
|
132
|
-
|
133
|
-
FIXME
|
134
|
-
|
135
|
-
self
|
64
|
+
gsub(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (_1 || _2) << '_' }
|
65
|
+
.tr('-', '_')
|
66
|
+
.downcase(*options)
|
136
67
|
end
|
137
68
|
|
138
69
|
# Converts camelcase boundaries to kebabcase.
|
@@ -143,8 +74,8 @@ module CrystalGoodies
|
|
143
74
|
# "HTTP_CLIENT".dasherize # => "http-client"
|
144
75
|
# "3.14IsPi".dasherize # => "3.14-is-pi"
|
145
76
|
# ```
|
146
|
-
def dasherize
|
147
|
-
underscore.tr('_', '-')
|
77
|
+
def dasherize(*options)
|
78
|
+
underscore(*options).tr('_', '-')
|
148
79
|
end
|
149
80
|
|
150
81
|
# Returns `true` if this string consists exclusively of unicode whitespace.
|
data/sig/enumerable.rbs
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystal_goodies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NNB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Class's methods port from Crystal.
|
13
|
+
description: Class's methods inspired/port from Crystal.
|
14
14
|
email:
|
15
15
|
- nnbnh@protonmail.com
|
16
16
|
executables: []
|