crystal_goodies 1.0.0 → 1.0.1

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: 100fad08a9578a26ae53785926cc01fc7d81735a7afe55c62d1a3d74d9312924
4
- data.tar.gz: c0bf1b1c3d290359d270659de2e888fa9486473eae55e517af9c38358c4367af
3
+ metadata.gz: d4b7ae551c485c71237af166ebd2290d65f1f2773aba36879c7f8ea26cdf2146
4
+ data.tar.gz: 10760bdbd7c24e1eb6f7fed9a44179fd747487e8962730f34f1afe8c12e2ec25
5
5
  SHA512:
6
- metadata.gz: 1eebd55c21f807d34ae9be8bacd3c12d645ff9eacc721314bdd19cd3c880091a39d873dee0f3d5e1e5cbd407a0574a695cdc25d5da7ee4fda01f2c5d19c32122
7
- data.tar.gz: f2d138d8a5b01fc8dc89e5913909e0c768332e43c9f1e07ffd2329b98238bc9f84b24316a270698ddff48f89bcd7b54ed2aeba32d334518ab4b253cc49510b69
6
+ metadata.gz: da29836bb1d4979e3f1e57d83c4c9c00297fcba47bd5160ebf987cc0ed29178ad0da84048bc504a169c2d6d737ce5bd93d5ca7a2c8e1276da522e342fc2627a0
7
+ data.tar.gz: 1658a8a130350d2cd70cffff5924f7a7ec122f238ec055601e1dacb3ca551e8367bf19319172bde7d4b8b9ba851928afdece04063060ce0ccde5ee1214a04a4f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.0.1] - 2023-08-16
2
+
3
+ - Fixed `String#underscore`.
4
+
1
5
  ## [1.0.0] - 2023-08-16
2
6
 
3
7
  - Initial release.
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&section=footer&color=DC2626&fontColor=FEF2F2&height=128&desc=Made%20with%20%26lt;3%20by%20NNB&descAlignY=80" /></a>
@@ -21,7 +21,6 @@ module CrystalGoodies
21
21
  # ["Alice", "Bob"].compact_map { |name| name.match(/^A./) } # => [#<MatchData "Al">]
22
22
  # ```
23
23
  def compact_map(&)
24
- # FIXME
25
24
  map(&).compact
26
25
  end
27
26
 
@@ -61,78 +61,9 @@ module CrystalGoodies
61
61
  # "3.14IsPi".underscore # => "3.14_is_pi"
62
62
  # ```
63
63
  def underscore(*options)
64
- <<-FIXME
65
-
66
- string = ''
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CrystalGoodies
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
data/sig/enumerable.rbs CHANGED
@@ -2,8 +2,7 @@ module CrystalGoodies
2
2
  module Enumerable
3
3
  def empty?: () -> bool
4
4
 
5
- def compact_map: () -> Enumerator
6
- | () { () -> void } -> Array
5
+ def compact_map: () { () -> void } -> Array
7
6
 
8
7
  def in_groups_of: (Integer size, ?untyped? filled_up_with) -> Array
9
8
 
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.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-15 00:00:00.000000000 Z
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: []