smartname 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/smart_name.rb +29 -29
- data/spec/lib/smart_name_spec.rb +19 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/smart_name.rb
CHANGED
@@ -43,13 +43,6 @@ class SmartName < Object
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def unescape uri
|
47
|
-
# can't instantiate because key doesn't resolve correctly in unescaped form
|
48
|
-
# issue is peculiar to plus sign (+), which are interpreted as a space.
|
49
|
-
# if we could make that not happen, we could avoid this (and handle spaces in urls)
|
50
|
-
uri.gsub(' ','+').gsub '_',' '
|
51
|
-
end
|
52
|
-
|
53
46
|
def banned_re
|
54
47
|
%r{#{ (['['] + SmartName.banned_array << SmartName.joint )*'\\' + ']' }}
|
55
48
|
end
|
@@ -136,35 +129,42 @@ class SmartName < Object
|
|
136
129
|
#~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
|
137
130
|
|
138
131
|
alias simple? simple
|
139
|
-
def junction?()
|
140
|
-
|
141
|
-
def left()
|
142
|
-
def right()
|
143
|
-
|
144
|
-
def left_name()
|
145
|
-
def right_name()
|
146
|
-
|
147
|
-
# Note that all
|
148
|
-
|
149
|
-
def trunk()
|
150
|
-
def tag()
|
151
|
-
|
152
|
-
def trunk_name()
|
153
|
-
def tag_name()
|
154
|
-
|
155
|
-
def part_names()
|
156
|
-
def
|
157
|
-
|
158
|
-
def
|
159
|
-
@
|
132
|
+
def junction?() not simple? end
|
133
|
+
|
134
|
+
def left() @left ||= simple? ? nil : parts[0..-2]*SmartName.joint end
|
135
|
+
def right() @right ||= simple? ? nil : parts[-1] end
|
136
|
+
|
137
|
+
def left_name() @left_name ||= left && SmartName.new( left ) end
|
138
|
+
def right_name() @right_name ||= right && SmartName.new( right ) end
|
139
|
+
|
140
|
+
# Note that all n ames have a trunk and tag, but only junctions have left and right
|
141
|
+
|
142
|
+
def trunk() @trunk ||= simple? ? s : left end
|
143
|
+
def tag() @tag ||= simple? ? s : right end
|
144
|
+
|
145
|
+
def trunk_name() @trunk_name ||= simple? ? self : left_name end
|
146
|
+
def tag_name() @tag_name ||= simple? ? self : right_name end
|
147
|
+
|
148
|
+
def part_names() @part_names ||= parts.map &:to_name end
|
149
|
+
def piece_names() @piece_names ||= pieces.map &:to_name end
|
150
|
+
|
151
|
+
def pieces
|
152
|
+
@pieces ||= if simple?
|
160
153
|
[ self ]
|
161
154
|
else
|
162
|
-
|
155
|
+
junction_pieces = []
|
156
|
+
parts[1..-1].inject parts[0] do |left, right|
|
157
|
+
piece = [left, right] * SmartName.joint
|
158
|
+
junction_pieces << piece
|
159
|
+
piece
|
160
|
+
end
|
161
|
+
parts + junction_pieces
|
163
162
|
end
|
164
163
|
end
|
165
164
|
|
166
165
|
|
167
166
|
|
167
|
+
|
168
168
|
#~~~~~~~~~~~~~~~~~~~ TRAITS / STARS ~~~~~~~~~~~~~~~~~~~
|
169
169
|
|
170
170
|
#all the below seems pretty wagn-specific
|
data/spec/lib/smart_name_spec.rb
CHANGED
@@ -64,6 +64,25 @@ describe SmartName do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
|
67
|
+
describe "parts and pieces" do
|
68
|
+
it "should produce simple strings for parts" do
|
69
|
+
"A+B+C+D".to_name.parts.should == %w{ A B C D }
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should produce simple name objects for part_names" do
|
73
|
+
"A+B+C+D".to_name.part_names.should == %w{ A B C D }.map( &:to_name )
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should produce compound strings for pieces" do
|
77
|
+
"A+B+C+D".to_name.pieces.should == %w{ A B C D A+B A+B+C A+B+C+D }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should produce compound name objects for piece_names" do
|
81
|
+
"A+B+C+D".to_name.piece_names.should == %w{ A B C D A+B A+B+C A+B+C+D }.map( &:to_name )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
67
86
|
|
68
87
|
|
69
88
|
|
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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: 3336685085994902956
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|