smartname 0.5.0 → 0.5.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/VERSION +1 -1
- data/lib/smart_name/contextual.rb +1 -0
- data/lib/smart_name/parts.rb +20 -18
- data/spec/lib/smart_name/contextual_spec.rb +4 -0
- data/spec/lib/smart_name/parts_spec.rb +4 -0
- data/spec/lib/smart_name_spec.rb +44 -30
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f612c29dbef138ab916ebcf8645fc67dfa7c7c09
|
4
|
+
data.tar.gz: 0501b8a442d67f73cd80bfae48c8d70b1a1703db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f7b99953fe2d1d8dd6953f5c277a96f1d2dc17ad2d736bbabc3f963a8e2ce697010859e606f8d86fd63e5b951910c7124b327ce5004d09048f9e8a072d42333
|
7
|
+
data.tar.gz: d1240995bc6ce9160f9363465395e81f7f51f5dadf93229596d6ba8b7cd28247463cefd575cb2f3b3e6f771bd21c4e9da32b57f82691231245ed2582c570e8ca
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/smart_name/parts.rb
CHANGED
@@ -7,15 +7,6 @@ class SmartName
|
|
7
7
|
|
8
8
|
alias simple? simple
|
9
9
|
alias_method :to_a, :parts
|
10
|
-
alias_method :to_ary, :parts
|
11
|
-
|
12
|
-
def to_ary
|
13
|
-
if parts.empty?
|
14
|
-
[""]
|
15
|
-
else
|
16
|
-
parts
|
17
|
-
end
|
18
|
-
end
|
19
10
|
|
20
11
|
def initialize_parts
|
21
12
|
# -1 = don't suppress trailing null fields
|
@@ -108,17 +99,28 @@ class SmartName
|
|
108
99
|
end
|
109
100
|
end
|
110
101
|
|
111
|
-
|
112
|
-
|
113
|
-
if parts.respond_to?(method)
|
114
|
-
self.class.new parts.send(method, *args, &block)
|
115
|
-
else
|
116
|
-
super
|
117
|
-
end
|
102
|
+
def + other
|
103
|
+
self.class.new(parts + other.to_name.parts)
|
118
104
|
end
|
119
105
|
|
120
|
-
def
|
121
|
-
|
106
|
+
def [] *args
|
107
|
+
self.class.new parts[*args]
|
122
108
|
end
|
109
|
+
|
110
|
+
# full support of array methods caused trouble with `flatten` calls
|
111
|
+
# It splits the parts of smartnames in arrays
|
112
|
+
# # name parts can be accessed and manipulated like an array
|
113
|
+
# def method_missing method, *args, &block
|
114
|
+
# if ARRAY_METHODS.include? method # parts.respond_to?(method)
|
115
|
+
# self.class.new parts.send(method, *args, &block)
|
116
|
+
# else
|
117
|
+
# super
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# def respond_to? method, include_private=false
|
122
|
+
# return true if ARRAY_METHODS.include? method
|
123
|
+
# super || parts.respond_to?(method, include_private)
|
124
|
+
# end
|
123
125
|
end
|
124
126
|
end
|
@@ -44,6 +44,10 @@ RSpec.describe SmartName::Contextual do
|
|
44
44
|
expect('_2+_3'.to_name.to_absolute('A+B+C')).to eq('B+C')
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'handles empty name' do
|
48
|
+
expect(''.to_name.to_absolute('A+B')).to eq('')
|
49
|
+
end
|
50
|
+
|
47
51
|
it 'handles _LLR etc' do
|
48
52
|
expect('_R'.to_name.to_absolute('A+B+C+D+E')).to eq('E')
|
49
53
|
expect('_L'.to_name.to_absolute('A+B+C+D+E')).to eq('A+B+C+D')
|
@@ -61,5 +61,9 @@ RSpec.describe SmartName::Parts do
|
|
61
61
|
it 'flatten preserves empty names' do
|
62
62
|
expect(["".to_name, "A"].flatten.to_name.s).to eq "+A"
|
63
63
|
end
|
64
|
+
|
65
|
+
it 'flatten preserves names' do
|
66
|
+
expect([["A+B".to_name], "C+D".to_name].flatten).to eq ["A+B".to_name, "C+D".to_name]
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
data/spec/lib/smart_name_spec.rb
CHANGED
@@ -2,63 +2,77 @@
|
|
2
2
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe SmartName do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
expect(
|
5
|
+
describe "#key" do
|
6
|
+
it "lowercases and underscores" do
|
7
|
+
expect("This Name".to_name.key).to eq("this_name")
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
expect(
|
10
|
+
it "removes spaces" do
|
11
|
+
expect("this Name".to_name.key).to eq("this_name")
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
describe "underscores" do
|
15
|
+
it "is treated like spaces" do
|
16
|
+
expect("weird_ combo".to_name.key).to eq("weird combo".to_name.key)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not impede pluralization checks" do
|
20
|
+
expect("Mamas_and_Papas".to_name.key).to(
|
21
|
+
eq("Mamas and Papas".to_name.key)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is removed when before first word character" do
|
26
|
+
expect("_This Name".to_name.key).to eq("this_name")
|
27
|
+
end
|
16
28
|
end
|
17
29
|
|
18
|
-
it
|
19
|
-
expect(
|
30
|
+
it "singularizes" do
|
31
|
+
expect("ethans".to_name.key).to eq("ethan")
|
20
32
|
end
|
21
33
|
|
22
|
-
it
|
23
|
-
expect(
|
34
|
+
it "changes CamelCase to snake case" do
|
35
|
+
expect("ThisThing".to_name.key).to eq("this_thing")
|
24
36
|
end
|
25
37
|
|
26
|
-
it
|
27
|
-
expect(
|
38
|
+
it "handles plus cards" do
|
39
|
+
expect("ThisThing+Ethans".to_name.key).to eq("this_thing+ethan")
|
28
40
|
end
|
29
41
|
|
30
|
-
it
|
31
|
-
expect(
|
42
|
+
it "retains * for star cards" do
|
43
|
+
expect("*right".to_name.key).to eq("*right")
|
32
44
|
end
|
33
45
|
|
34
|
-
it "
|
35
|
-
expect(
|
46
|
+
it "does not singularize double s's" do
|
47
|
+
expect("grass".to_name.key).to eq("grass")
|
36
48
|
end
|
37
49
|
|
38
|
-
it "
|
39
|
-
expect(
|
50
|
+
it "does not singularize letter 'S'" do
|
51
|
+
expect("S".to_name.key).to eq("s")
|
40
52
|
end
|
41
53
|
|
42
|
-
it
|
43
|
-
expect(
|
54
|
+
it "handles unicode characters" do
|
55
|
+
expect("Mañana".to_name.key).to eq("mañana")
|
44
56
|
end
|
45
57
|
|
46
|
-
it
|
47
|
-
expect(
|
48
|
-
expect(
|
58
|
+
it "handles weird initial characters" do
|
59
|
+
expect("__you motha @\#$".to_name.key).to eq("you_motha")
|
60
|
+
expect("?!_you motha @\#$".to_name.key).to eq("you_motha")
|
49
61
|
end
|
50
62
|
|
51
|
-
it
|
52
|
-
expect(
|
63
|
+
it "allows numbers" do
|
64
|
+
expect("3way".to_name.key).to eq("3way")
|
53
65
|
end
|
54
66
|
|
55
|
-
it
|
56
|
-
expect(
|
67
|
+
it "internal plurals" do
|
68
|
+
expect("cards hooks label foos".to_name.key).to eq("card_hook_label_foo")
|
57
69
|
end
|
58
70
|
|
59
|
-
it
|
71
|
+
it "handles html entities" do
|
60
72
|
# This no longer takes off the s, is singularize broken now?
|
61
|
-
expect(
|
73
|
+
expect("Jean-françois Noubel".to_name.key).to(
|
74
|
+
eq("jean_françoi_noubel")
|
75
|
+
)
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|