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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db3a78f4a254d599ca83a93a19d14a61a37c8b05
4
- data.tar.gz: 1889454b39276d368ea7ae05b53e255c9f559490
3
+ metadata.gz: f612c29dbef138ab916ebcf8645fc67dfa7c7c09
4
+ data.tar.gz: 0501b8a442d67f73cd80bfae48c8d70b1a1703db
5
5
  SHA512:
6
- metadata.gz: aa470ffc741acea8d1d3b3e22c9a61d8b79de9f2f2650c5f08d669e7920bc1c237cdd4310f6cbfef8ab8ccde0243a64dfc07cfd4895bbdafe14b19aa5f9ff8cf
7
- data.tar.gz: 50be6deee20d1b2c0554645786be70167ceaf8b41147fe982dc42fac5d59d84290ffc1952c39e5a05251bada945244534817bf532ba3e0a151d3963d86902cc7
6
+ metadata.gz: 5f7b99953fe2d1d8dd6953f5c277a96f1d2dc17ad2d736bbabc3f963a8e2ce697010859e606f8d86fd63e5b951910c7124b327ce5004d09048f9e8a072d42333
7
+ data.tar.gz: d1240995bc6ce9160f9363465395e81f7f51f5dadf93229596d6ba8b7cd28247463cefd575cb2f3b3e6f771bd21c4e9da32b57f82691231245ed2582c570e8ca
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -58,6 +58,7 @@ class SmartName
58
58
  context = context.to_name
59
59
 
60
60
  new_parts = replace_contextual_parts context
61
+ return "" if new_parts.empty?
61
62
 
62
63
  if new_parts.first.empty? && !new_parts.to_name.starts_with?(context)
63
64
  new_parts[0] = context.to_s
@@ -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
- # name parts can be accessed and manipulated like an array
112
- def method_missing method, *args, &block
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 respond_to? method, include_private=false
121
- super || parts.respond_to?(method, include_private)
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
@@ -2,63 +2,77 @@
2
2
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
3
3
 
4
4
  describe SmartName do
5
- describe '#key' do
6
- it 'should remove spaces' do
7
- expect('this Name'.to_name.key).to eq('this_name')
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 'should have initial _ for initial cap' do
11
- expect('This Name'.to_name.key).to eq('this_name')
10
+ it "removes spaces" do
11
+ expect("this Name".to_name.key).to eq("this_name")
12
12
  end
13
13
 
14
- it 'should have initial _ for initial cap' do
15
- expect('_This Name'.to_name.key).to eq('this_name')
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 'should singularize' do
19
- expect('ethans'.to_name.key).to eq('ethan')
30
+ it "singularizes" do
31
+ expect("ethans".to_name.key).to eq("ethan")
20
32
  end
21
33
 
22
- it 'should underscore' do
23
- expect('ThisThing'.to_name.key).to eq('this_thing')
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 'should handle plus cards' do
27
- expect('ThisThing+Ethans'.to_name.key).to eq('this_thing+ethan')
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 'should retain * for star cards' do
31
- expect('*right'.to_name.key).to eq('*right')
42
+ it "retains * for star cards" do
43
+ expect("*right".to_name.key).to eq("*right")
32
44
  end
33
45
 
34
- it "should not singularize double s's" do
35
- expect('grass'.to_name.key).to eq('grass')
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 "should not singularize letter 'S'" do
39
- expect('S'.to_name.key).to eq('s')
50
+ it "does not singularize letter 'S'" do
51
+ expect("S".to_name.key).to eq("s")
40
52
  end
41
53
 
42
- it 'should handle unicode characters' do
43
- expect('Mañana'.to_name.key).to eq('mañana')
54
+ it "handles unicode characters" do
55
+ expect("Mañana".to_name.key).to eq("mañana")
44
56
  end
45
57
 
46
- it 'should handle weird initial characters' do
47
- expect('__you motha @#$'.to_name.key).to eq('you_motha')
48
- expect('?!_you motha @#$'.to_name.key).to eq('you_motha')
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 'should allow numbers' do
52
- expect('3way'.to_name.key).to eq('3way')
63
+ it "allows numbers" do
64
+ expect("3way".to_name.key).to eq("3way")
53
65
  end
54
66
 
55
- it 'internal plurals' do
56
- expect('cards hooks label foos'.to_name.key).to eq('card_hook_label_foo')
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 'should handle html entities' do
71
+ it "handles html entities" do
60
72
  # This no longer takes off the s, is singularize broken now?
61
- expect('Jean-françois Noubel'.to_name.key).to eq('jean_françoi_noubel')
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartname
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerry Gleason