babosa 2.0.0.beta → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +1 -2
- data/lib/babosa/identifier.rb +28 -14
- data/lib/babosa/version.rb +1 -1
- data/spec/identifier_spec.rb +4 -4
- metadata +34 -7
- metadata.gz.sig +2 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84fa74468828d44925314cc1bcf6d297aa3a94ebfd993bca491686c92c936667
|
4
|
+
data.tar.gz: 618a52e9d52878fe8bc5933879115d32dd31b212a9cd2178e78bb7320d186c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d86867859c5af0f8f80631b5d7aefe14cf87d61ec5908fa08d68fa38cc2e287c77c2c59c41377eb41e6524ba723ed511d1d09e5837259aad4a1ced7162c25a
|
7
|
+
data.tar.gz: 005dbd796a469420ddc905e2fcf4261703f3777ab29000102039e52b907d51d51c3ab69f11779bfc3e76ed19c24fad997733d008c7d08f50dc1446fa230b7e3d
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Babosa
|
2
2
|
|
3
|
-
[![Build Status](https://
|
4
|
-
|
3
|
+
[![Build Status](https://github.com/norman/babosa/actions/workflows/main.yml/badge.svg)](https://github.com/norman/babosa/actions)
|
5
4
|
|
6
5
|
Babosa is a library for creating human-friendly identifiers, aka "slugs". It can
|
7
6
|
also be useful for normalizing and sanitizing data.
|
data/lib/babosa/identifier.rb
CHANGED
@@ -110,7 +110,7 @@ module Babosa
|
|
110
110
|
# `^\p{letter}` = Any non-Unicode letter
|
111
111
|
# `&&` = add the following character class
|
112
112
|
# `[^ _\n\r]` = Anything other than space, underscore, newline or linefeed
|
113
|
-
gsub!(/[[^\p{letter}]&&[^
|
113
|
+
gsub!(/[[^\p{letter}]&&[^ \d_\-\n\r]]/, "")
|
114
114
|
to_s
|
115
115
|
end
|
116
116
|
|
@@ -125,10 +125,10 @@ module Babosa
|
|
125
125
|
|
126
126
|
if options[:transliterate]
|
127
127
|
option = options[:transliterate]
|
128
|
-
if option
|
129
|
-
transliterate!(*option)
|
130
|
-
else
|
128
|
+
if option == true
|
131
129
|
transliterate!(*options[:transliterations])
|
130
|
+
else
|
131
|
+
transliterate!(*option)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
to_ascii! if options[:to_ascii]
|
@@ -148,6 +148,7 @@ module Babosa
|
|
148
148
|
transliterate!
|
149
149
|
to_ascii!
|
150
150
|
word_chars!
|
151
|
+
strip_leading_digits!
|
151
152
|
clean!
|
152
153
|
@wrapped_string += last_char if allow_bangs && ["!", "?"].include?(last_char)
|
153
154
|
raise Error, "Input generates impossible Ruby method name" if self == ""
|
@@ -206,6 +207,14 @@ module Babosa
|
|
206
207
|
to_s
|
207
208
|
end
|
208
209
|
|
210
|
+
# Strip any leading digits.
|
211
|
+
#
|
212
|
+
# @return String
|
213
|
+
def strip_leading_digits!
|
214
|
+
gsub!(/^\d+/, "")
|
215
|
+
to_s
|
216
|
+
end
|
217
|
+
|
209
218
|
# Attempt to convert characters encoded using CP1252 and IS0-8859-1 to
|
210
219
|
# UTF-8.
|
211
220
|
# @return String
|
@@ -216,16 +225,20 @@ module Babosa
|
|
216
225
|
to_s
|
217
226
|
end
|
218
227
|
|
219
|
-
%w[
|
220
|
-
tidy_bytes to_ascii
|
221
|
-
with_separators].each do |method|
|
228
|
+
%w[clean downcase normalize normalize_utf8 strip_leading_digits
|
229
|
+
tidy_bytes to_ascii transliterate truncate truncate_bytes upcase
|
230
|
+
with_separators word_chars].each do |method|
|
222
231
|
class_eval(<<-METHOD, __FILE__, __LINE__ + 1)
|
223
232
|
def #{method}(*args)
|
224
|
-
|
233
|
+
with_new_instance { |id| id.send(:#{method}!, *args) }
|
225
234
|
end
|
226
235
|
METHOD
|
227
236
|
end
|
228
237
|
|
238
|
+
def to_ruby_method(allow_bangs: true)
|
239
|
+
with_new_instance { |id| id.to_ruby_method!(allow_bangs: allow_bangs) }
|
240
|
+
end
|
241
|
+
|
229
242
|
def to_identifier
|
230
243
|
self
|
231
244
|
end
|
@@ -243,12 +256,13 @@ module Babosa
|
|
243
256
|
|
244
257
|
private
|
245
258
|
|
246
|
-
# Used as the basis of the bangless methods.
|
247
|
-
def
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
259
|
+
# Used as the basis of the non-mutating (bangless) methods.
|
260
|
+
def with_new_instance
|
261
|
+
Identifier.allocate.tap do |id|
|
262
|
+
id.instance_variable_set :@wrapped_string, to_s
|
263
|
+
|
264
|
+
yield id
|
265
|
+
end
|
252
266
|
end
|
253
267
|
end
|
254
268
|
end
|
data/lib/babosa/version.rb
CHANGED
data/spec/identifier_spec.rb
CHANGED
@@ -16,9 +16,9 @@ describe Babosa::Identifier do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#word_chars" do
|
19
|
-
it "word_chars! should leave only letters and spaces" do
|
20
|
-
string = "a*$%^$@!@b$%^&*()*!c"
|
21
|
-
expect(string.to_slug.word_chars!).to
|
19
|
+
it "word_chars! should leave only letters, numbers, and spaces" do
|
20
|
+
string = "a*$%^$@!@b$%^&*()*!c 123"
|
21
|
+
expect(string.to_slug.word_chars!).to eq "abc 123"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -139,6 +139,7 @@ describe Babosa::Identifier do
|
|
139
139
|
expect("カタカナ: katakana is über cool".to_slug.to_ruby_method).to eql("katakana_is_uber_cool")
|
140
140
|
expect("カタカナ: katakana is über cool!".to_slug.to_ruby_method).to eql("katakana_is_uber_cool!")
|
141
141
|
expect("カタカナ: katakana is über cool".to_slug.to_ruby_method(allow_bangs: false)).to eql("katakana_is_uber_cool")
|
142
|
+
expect("not 2 much 4 ruby".to_slug.to_ruby_method).to eql("not_2_much_4_ruby")
|
142
143
|
end
|
143
144
|
|
144
145
|
it "should optionally remove trailing punctuation" do
|
@@ -146,7 +147,6 @@ describe Babosa::Identifier do
|
|
146
147
|
end
|
147
148
|
|
148
149
|
it "should raise an error when it would generate an impossible method name" do
|
149
|
-
# "1".to_identifier.to_ruby_method
|
150
150
|
expect { "1".to_identifier.to_ruby_method }.to raise_error(Babosa::Identifier::Error)
|
151
151
|
end
|
152
152
|
|
metadata
CHANGED
@@ -1,14 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babosa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
|
14
|
+
L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjEwNjIzMDkyNzU2WhcNMjIwNjIzMDky
|
15
|
+
NzU2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
|
16
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQD0CYnD37uLlJ3Urla2EnnUQ8S6s16k
|
17
|
+
AGMpAzpmARo8YwSqtYMJVGyBzUeI7y93Fk9ncswhIFSH/hnh/Ouat/ki9flHlZ+w
|
18
|
+
anv0M+9v3wCLyZSC5BQIWpoduFM/fuvLoDUJDWxL50RjwMS0qo2x2LvfQdHN8gn3
|
19
|
+
JdSIV5WLJKIvlmIl9S3pw0JO5KRUGn1PcBO7C0S0SlbhVjRHtlao1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WRforZEZi+qamognrozd3MI5QHi1W
|
35
|
+
UAZUzHLrrFu7gnkFvLVpxOUf4ItOkA==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
date: 2021-08-01 00:00:00.000000000 Z
|
12
38
|
dependencies:
|
13
39
|
- !ruby/object:Gem::Dependency
|
14
40
|
name: rake
|
@@ -122,7 +148,8 @@ files:
|
|
122
148
|
- spec/transliterators/ukrainian_spec.rb
|
123
149
|
- spec/transliterators/vietnamese_spec.rb
|
124
150
|
homepage: http://github.com/norman/babosa
|
125
|
-
licenses:
|
151
|
+
licenses:
|
152
|
+
- MIT
|
126
153
|
metadata: {}
|
127
154
|
post_install_message:
|
128
155
|
rdoc_options: []
|
@@ -135,11 +162,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
162
|
version: 2.5.0
|
136
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
164
|
requirements:
|
138
|
-
- - "
|
165
|
+
- - ">="
|
139
166
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
167
|
+
version: '0'
|
141
168
|
requirements: []
|
142
|
-
rubygems_version: 3.1.
|
169
|
+
rubygems_version: 3.1.6
|
143
170
|
signing_key:
|
144
171
|
specification_version: 4
|
145
172
|
summary: A library for creating slugs.
|
metadata.gz.sig
ADDED