smartname 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cardname.rb +258 -0
- data/lib/smart_name.rb +2 -2
- data/orig_cardname.rb +258 -0
- metadata +18 -46
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/cardname.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wagn
|
3
|
+
class SmartName < Object
|
4
|
+
require 'htmlentities'
|
5
|
+
|
6
|
+
JOINT = '+'
|
7
|
+
JOINT_RE = Regexp.escape JOINT
|
8
|
+
BANNED_ARRAY = [ '/', '~', '|' ]
|
9
|
+
BANNED_RE = /#{ (['['] + BANNED_ARRAY << JOINT )*'\\' }]/
|
10
|
+
|
11
|
+
RUBY19 = RUBY_VERSION =~ /^1\.9/
|
12
|
+
OK4KEY_RE = RUBY19 ? '\p{Word}\*' : '\w\*'
|
13
|
+
|
14
|
+
@@name2nameobject = {}
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def new obj
|
18
|
+
return obj if SmartName===obj
|
19
|
+
str = Array===obj ? obj*SmartName.joint : obj.to_s
|
20
|
+
if known_name = @@name2nameobject[str]
|
21
|
+
known_name
|
22
|
+
else
|
23
|
+
super str.strip
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def unescape uri
|
28
|
+
# can't instantiate because key doesn't resolve correctly in unescaped form
|
29
|
+
# issue is peculiar to plus sign (+), which are interpreted as a space.
|
30
|
+
# if we could make that not happen, we could avoid this (and handle spaces in urls)
|
31
|
+
uri.gsub(' ','+').gsub '_',' '
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
37
|
+
#~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~
|
38
|
+
|
39
|
+
attr_reader :simple, :parts, :key, :s
|
40
|
+
alias to_s s
|
41
|
+
|
42
|
+
def initialize str
|
43
|
+
@s = str.to_s.strip
|
44
|
+
@s = @s.encode('UTF-8') if RUBY19
|
45
|
+
@key = if @s.index(SmartName.joint)
|
46
|
+
@parts = @s.split(/\s*#{SmartName.joint}\s*/)
|
47
|
+
@parts << '' if @s.last == SmartName.joint
|
48
|
+
@simple = false
|
49
|
+
@parts.map { |p| p.to_name.key } * SmartName.joint
|
50
|
+
else
|
51
|
+
@parts = [str]
|
52
|
+
@simple = true
|
53
|
+
str.blank? ? '' : simple_key
|
54
|
+
end
|
55
|
+
@@name2nameobject[str] = self
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_name() self end
|
59
|
+
def valid?() not parts.find { |pt| pt.match BANNED_RE } end
|
60
|
+
def size() parts.size end # size of name = number of parts?? not intuitive. maybe depth? psize?
|
61
|
+
def blank?() s.blank? end
|
62
|
+
alias empty? blank?
|
63
|
+
|
64
|
+
def inspect
|
65
|
+
"<SmartName key=#{key}[#{self}]>"
|
66
|
+
end
|
67
|
+
|
68
|
+
def == obj
|
69
|
+
object_key = case
|
70
|
+
when obj.respond_to?(:key) ; obj.key
|
71
|
+
when obj.respond_to?(:to_name) ; obj.to_name.key
|
72
|
+
else ; obj.to_s
|
73
|
+
end
|
74
|
+
object_key == key
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#~~~~~~~~~~~~~~~~~~~ VARIANTS ~~~~~~~~~~~~~~~~~~~
|
79
|
+
|
80
|
+
def simple_key
|
81
|
+
decoded.underscore.gsub(/[^#{OK4KEY_RE}]+/,'_').split(/_+/).reject(&:blank?).map(&:singularize)*'_'
|
82
|
+
end
|
83
|
+
|
84
|
+
def url_key
|
85
|
+
@url_key ||= decoded.gsub(/[^#{OK4KEY_RE}#{JOINT_RE}]+/,' ').strip.gsub /[\s\_]+/, '_'
|
86
|
+
end
|
87
|
+
|
88
|
+
def safe_key
|
89
|
+
@safe_key ||= key.gsub('*','X').gsub SmartName.joint, '-'
|
90
|
+
end
|
91
|
+
|
92
|
+
def decoded
|
93
|
+
@decoded ||= (s.index('&') ? HTMLEntities.new.decode(s) : s)
|
94
|
+
end
|
95
|
+
|
96
|
+
def pre_cgi
|
97
|
+
#why is this necessary?? doesn't real CGI escaping handle this??
|
98
|
+
# hmmm. is this to prevent absolutizing
|
99
|
+
@pre_cgi ||= parts.join '~plus~'
|
100
|
+
end
|
101
|
+
|
102
|
+
def post_cgi
|
103
|
+
#hmm. this could resolve to the key of some other card. move to class method?
|
104
|
+
@post_cgi ||= s.gsub '~plus~', SmartName.joint
|
105
|
+
end
|
106
|
+
|
107
|
+
#~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
|
108
|
+
|
109
|
+
alias simple? simple
|
110
|
+
def junction?() not simple? end
|
111
|
+
|
112
|
+
def left() @left ||= simple? ? nil : parts[0..-2]*SmartName.joint end
|
113
|
+
def right() @right ||= simple? ? nil : parts[-1] end
|
114
|
+
|
115
|
+
def left_name() @left_name ||= left && self.class.new( left ) end
|
116
|
+
def right_name() @right_name ||= right && self.class.new( right ) end
|
117
|
+
|
118
|
+
# Note that all names have a trunk and tag, but only junctions have left and right
|
119
|
+
|
120
|
+
def trunk() @trunk ||= simple? ? s : left end
|
121
|
+
def tag() @tag ||= simple? ? s : right end
|
122
|
+
|
123
|
+
def trunk_name() @trunk_name ||= simple? ? self : left_name end
|
124
|
+
def tag_name() @tag_name ||= simple? ? self : right_name end
|
125
|
+
|
126
|
+
def pieces
|
127
|
+
@pieces ||= if simple?
|
128
|
+
[ self ]
|
129
|
+
else
|
130
|
+
trunk_name.pieces + [ tag_name ]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
#~~~~~~~~~~~~~~~~~~~ TRAITS / STARS ~~~~~~~~~~~~~~~~~~~
|
136
|
+
|
137
|
+
# note that [0] breaks in ruby 1.8.x but [0,1] doesn't
|
138
|
+
def star?() simple? and '*' == s[0,1] end
|
139
|
+
def rstar?() right and '*' == right[0,1] end
|
140
|
+
|
141
|
+
def trait_name? *traitlist
|
142
|
+
junction? && begin
|
143
|
+
right_key = right_name.key
|
144
|
+
!!traitlist.find do |codename|
|
145
|
+
Card[ codename ].cardname.key == right_key
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def trait_name tag_code
|
151
|
+
[ self, Card[ tag_code ].name ].to_name
|
152
|
+
end
|
153
|
+
|
154
|
+
def trait tag_code
|
155
|
+
trait_name( tag_code ).s
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
#~~~~~~~~~~~~~~~~~~~~ SHOW / ABSOLUTE ~~~~~~~~~~~~~~~~~~~~
|
161
|
+
|
162
|
+
def to_show context, args={}
|
163
|
+
# ignore = [ args[:ignore], context.to_name.parts ].flatten.compact.map &:to_name
|
164
|
+
ignore = [ args[:ignore] ].flatten.map &:to_name
|
165
|
+
fullname = parts.to_name.to_absolute_name context, args
|
166
|
+
|
167
|
+
show_parts = fullname.parts.map do |part|
|
168
|
+
reject = ( part.blank? or part =~ /^_/ or ignore.member? part.to_name )
|
169
|
+
reject ? nil : part
|
170
|
+
end
|
171
|
+
|
172
|
+
show_name = show_parts.compact.to_name.s
|
173
|
+
|
174
|
+
case
|
175
|
+
when show_parts.compact.empty?; fullname
|
176
|
+
when show_parts[0].nil? ; SmartName.joint + show_name
|
177
|
+
else show_name
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def to_absolute context, args={}
|
183
|
+
context = context.to_name
|
184
|
+
parts.map do |part|
|
185
|
+
new_part = case part
|
186
|
+
when /^_user$/i; (user=Session.user_card) ? user.name : part
|
187
|
+
when /^_main$/i; Wagn::Conf[:main_name]
|
188
|
+
when /^(_self|_whole|_)$/i; context.s
|
189
|
+
when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
|
190
|
+
when /^_right$/i; context.tag
|
191
|
+
when /^_(\d+)$/i
|
192
|
+
pos = $~[1].to_i
|
193
|
+
pos = context.size if pos > context.size
|
194
|
+
context.parts[pos-1]
|
195
|
+
when /^_(L*)(R?)$/i
|
196
|
+
l_s, r_s = $~[1].size, !$~[2].blank?
|
197
|
+
l_part = context.nth_left l_s
|
198
|
+
r_s ? l_part.tag : l_part.s
|
199
|
+
when /^_/
|
200
|
+
custom = args[:params] ? args[:params][part] : nil
|
201
|
+
custom ? CGI.escapeHTML(custom) : part #why are we escaping HTML here?
|
202
|
+
else
|
203
|
+
part
|
204
|
+
end.to_s.strip
|
205
|
+
new_part.blank? ? context.to_s : new_part
|
206
|
+
end * SmartName.joint
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_absolute_name *args
|
210
|
+
self.class.new to_absolute(*args)
|
211
|
+
end
|
212
|
+
|
213
|
+
def nth_left n
|
214
|
+
# 1 = left; 2= left of left; 3 = left of left of left....
|
215
|
+
( n >= size ? parts[0] : parts[0..-n-1] ).to_name
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
#~~~~~~~~~~~~~~~~~~~~ MISC ~~~~~~~~~~~~~~~~~~~~
|
220
|
+
|
221
|
+
def replace_part oldpart, newpart
|
222
|
+
oldpart = oldpart.to_name
|
223
|
+
newpart = newpart.to_name
|
224
|
+
if oldpart.simple?
|
225
|
+
if simple?
|
226
|
+
self == oldpart ? newpart : self
|
227
|
+
else
|
228
|
+
parts.map do |p|
|
229
|
+
oldpart == p ? newpart.to_s : p
|
230
|
+
end.to_name
|
231
|
+
end
|
232
|
+
elsif simple?
|
233
|
+
self
|
234
|
+
else
|
235
|
+
if oldpart == parts[0, oldpart.size]
|
236
|
+
if self.size == oldpart.size
|
237
|
+
newpart
|
238
|
+
else
|
239
|
+
(newpart.parts+(parts[oldpart.size,].lines.to_a)).to_name
|
240
|
+
end
|
241
|
+
else
|
242
|
+
self
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.substitute! str, hash
|
248
|
+
# HACK. This doesn't belong here.
|
249
|
+
# shouldn't thus use inclusions???
|
250
|
+
hash.keys.each do |var|
|
251
|
+
str.gsub!(/\{(#{var})\}/) {|x| hash[var.to_sym]}
|
252
|
+
end
|
253
|
+
str
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
data/lib/smart_name.rb
CHANGED
@@ -17,7 +17,7 @@ class SmartName < Object
|
|
17
17
|
include ActiveSupport::Configurable
|
18
18
|
|
19
19
|
config_accessor :joint, :formal_joint, :name_attribute, :banned_array,
|
20
|
-
:var_re, :uninflect, :params, :codes, :lookup
|
20
|
+
:var_re, :uninflect, :params, :codes, :lookup, :session
|
21
21
|
|
22
22
|
# Wagny defaults:
|
23
23
|
SmartName.joint = '+'
|
@@ -217,7 +217,7 @@ class SmartName < Object
|
|
217
217
|
context = context.to_name
|
218
218
|
parts.map do |part|
|
219
219
|
new_part = case part
|
220
|
-
when /^_user$/i;
|
220
|
+
when /^_user$/i; name_proc = SmartName.session and name_proc.call or part
|
221
221
|
when /^_main$/i; SmartName.params[:main_name]
|
222
222
|
when /^(_self|_whole|_)$/i; context.s
|
223
223
|
when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
|
data/orig_cardname.rb
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Wagn
|
3
|
+
class Cardname < Object
|
4
|
+
require 'htmlentities'
|
5
|
+
|
6
|
+
JOINT = '+'
|
7
|
+
JOINT_RE = Regexp.escape JOINT
|
8
|
+
BANNED_ARRAY = [ '/', '~', '|' ]
|
9
|
+
BANNED_RE = /#{ (['['] + BANNED_ARRAY << JOINT )*'\\' }]/
|
10
|
+
|
11
|
+
RUBY19 = RUBY_VERSION =~ /^1\.9/
|
12
|
+
OK4KEY_RE = RUBY19 ? '\p{Word}\*' : '\w\*'
|
13
|
+
|
14
|
+
@@name2cardname = {}
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def new obj
|
18
|
+
return obj if Cardname===obj
|
19
|
+
str = Array===obj ? obj*JOINT : obj.to_s
|
20
|
+
if known_name = @@name2cardname[str]
|
21
|
+
known_name
|
22
|
+
else
|
23
|
+
super str.strip
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def unescape uri
|
28
|
+
# can't instantiate because key doesn't resolve correctly in unescaped form
|
29
|
+
# issue is peculiar to plus sign (+), which are interpreted as a space.
|
30
|
+
# if we could make that not happen, we could avoid this (and handle spaces in urls)
|
31
|
+
uri.gsub(' ','+').gsub '_',' '
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
37
|
+
#~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~
|
38
|
+
|
39
|
+
attr_reader :simple, :parts, :key, :s
|
40
|
+
alias to_s s
|
41
|
+
|
42
|
+
def initialize str
|
43
|
+
@s = str.to_s.strip
|
44
|
+
@s = @s.encode('UTF-8') if RUBY19
|
45
|
+
@key = if @s.index(JOINT)
|
46
|
+
@parts = @s.split(/\s*#{JOINT_RE}\s*/)
|
47
|
+
@parts << '' if @s.last == JOINT
|
48
|
+
@simple = false
|
49
|
+
@parts.map { |p| p.to_cardname.key } * JOINT
|
50
|
+
else
|
51
|
+
@parts = [str]
|
52
|
+
@simple = true
|
53
|
+
str.blank? ? '' : simple_key
|
54
|
+
end
|
55
|
+
@@name2cardname[str] = self
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_cardname() self end
|
59
|
+
def valid?() not parts.find { |pt| pt.match BANNED_RE } end
|
60
|
+
def size() parts.size end # size of name = number of parts?? not intuitive. maybe depth? psize?
|
61
|
+
def blank?() s.blank? end
|
62
|
+
alias empty? blank?
|
63
|
+
|
64
|
+
def inspect
|
65
|
+
"<CardName key=#{key}[#{self}]>"
|
66
|
+
end
|
67
|
+
|
68
|
+
def == obj
|
69
|
+
object_key = case
|
70
|
+
when obj.respond_to?(:key) ; obj.key
|
71
|
+
when obj.respond_to?(:to_cardname) ; obj.to_cardname.key
|
72
|
+
else ; obj.to_s
|
73
|
+
end
|
74
|
+
object_key == key
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#~~~~~~~~~~~~~~~~~~~ VARIANTS ~~~~~~~~~~~~~~~~~~~
|
79
|
+
|
80
|
+
def simple_key
|
81
|
+
decoded.underscore.gsub(/[^#{OK4KEY_RE}]+/,'_').split(/_+/).reject(&:blank?).map(&:singularize)*'_'
|
82
|
+
end
|
83
|
+
|
84
|
+
def url_key
|
85
|
+
@url_key ||= decoded.gsub(/[^#{OK4KEY_RE}#{JOINT_RE}]+/,' ').strip.gsub /[\s\_]+/, '_'
|
86
|
+
end
|
87
|
+
|
88
|
+
def safe_key
|
89
|
+
@safe_key ||= key.gsub('*','X').gsub JOINT, '-'
|
90
|
+
end
|
91
|
+
|
92
|
+
def decoded
|
93
|
+
@decoded ||= (s.index('&') ? HTMLEntities.new.decode(s) : s)
|
94
|
+
end
|
95
|
+
|
96
|
+
def pre_cgi
|
97
|
+
#why is this necessary?? doesn't real CGI escaping handle this??
|
98
|
+
# hmmm. is this to prevent absolutizing
|
99
|
+
@pre_cgi ||= parts.join '~plus~'
|
100
|
+
end
|
101
|
+
|
102
|
+
def post_cgi
|
103
|
+
#hmm. this could resolve to the key of some other card. move to class method?
|
104
|
+
@post_cgi ||= s.gsub '~plus~', JOINT
|
105
|
+
end
|
106
|
+
|
107
|
+
#~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
|
108
|
+
|
109
|
+
alias simple? simple
|
110
|
+
def junction?() not simple? end
|
111
|
+
|
112
|
+
def left() @left ||= simple? ? nil : parts[0..-2]*JOINT end
|
113
|
+
def right() @right ||= simple? ? nil : parts[-1] end
|
114
|
+
|
115
|
+
def left_name() @left_name ||= left && self.class.new( left ) end
|
116
|
+
def right_name() @right_name ||= right && self.class.new( right ) end
|
117
|
+
|
118
|
+
# Note that all names have a trunk and tag, but only junctions have left and right
|
119
|
+
|
120
|
+
def trunk() @trunk ||= simple? ? s : left end
|
121
|
+
def tag() @tag ||= simple? ? s : right end
|
122
|
+
|
123
|
+
def trunk_name() @trunk_name ||= simple? ? self : left_name end
|
124
|
+
def tag_name() @tag_name ||= simple? ? self : right_name end
|
125
|
+
|
126
|
+
def pieces
|
127
|
+
@pieces ||= if simple?
|
128
|
+
[ self ]
|
129
|
+
else
|
130
|
+
trunk_name.pieces + [ tag_name ]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
#~~~~~~~~~~~~~~~~~~~ TRAITS / STARS ~~~~~~~~~~~~~~~~~~~
|
136
|
+
|
137
|
+
# note that [0] breaks in ruby 1.8.x but [0,1] doesn't
|
138
|
+
def star?() simple? and '*' == s[0,1] end
|
139
|
+
def rstar?() right and '*' == right[0,1] end
|
140
|
+
|
141
|
+
def trait_name? *traitlist
|
142
|
+
junction? && begin
|
143
|
+
right_key = right_name.key
|
144
|
+
!!traitlist.find do |codename|
|
145
|
+
Card[ codename ].cardname.key == right_key
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def trait_name tag_code
|
151
|
+
[ self, Card[ tag_code ].name ].to_cardname
|
152
|
+
end
|
153
|
+
|
154
|
+
def trait tag_code
|
155
|
+
trait_name( tag_code ).s
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
#~~~~~~~~~~~~~~~~~~~~ SHOW / ABSOLUTE ~~~~~~~~~~~~~~~~~~~~
|
161
|
+
|
162
|
+
def to_show context, args={}
|
163
|
+
# ignore = [ args[:ignore], context.to_cardname.parts ].flatten.compact.map &:to_cardname
|
164
|
+
ignore = [ args[:ignore] ].flatten.map &:to_cardname
|
165
|
+
fullname = parts.to_cardname.to_absolute_name context, args
|
166
|
+
|
167
|
+
show_parts = fullname.parts.map do |part|
|
168
|
+
reject = ( part.blank? or part =~ /^_/ or ignore.member? part.to_cardname )
|
169
|
+
reject ? nil : part
|
170
|
+
end
|
171
|
+
|
172
|
+
show_name = show_parts.compact.to_cardname.s
|
173
|
+
|
174
|
+
case
|
175
|
+
when show_parts.compact.empty?; fullname
|
176
|
+
when show_parts[0].nil? ; JOINT + show_name
|
177
|
+
else show_name
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def to_absolute context, args={}
|
183
|
+
context = context.to_cardname
|
184
|
+
parts.map do |part|
|
185
|
+
new_part = case part
|
186
|
+
when /^_user$/i; (user=Session.user_card) ? user.name : part
|
187
|
+
when /^_main$/i; Wagn::Conf[:main_name]
|
188
|
+
when /^(_self|_whole|_)$/i; context.s
|
189
|
+
when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
|
190
|
+
when /^_right$/i; context.tag
|
191
|
+
when /^_(\d+)$/i
|
192
|
+
pos = $~[1].to_i
|
193
|
+
pos = context.size if pos > context.size
|
194
|
+
context.parts[pos-1]
|
195
|
+
when /^_(L*)(R?)$/i
|
196
|
+
l_s, r_s = $~[1].size, !$~[2].blank?
|
197
|
+
l_part = context.nth_left l_s
|
198
|
+
r_s ? l_part.tag : l_part.s
|
199
|
+
when /^_/
|
200
|
+
custom = args[:params] ? args[:params][part] : nil
|
201
|
+
custom ? CGI.escapeHTML(custom) : part #why are we escaping HTML here?
|
202
|
+
else
|
203
|
+
part
|
204
|
+
end.to_s.strip
|
205
|
+
new_part.blank? ? context.to_s : new_part
|
206
|
+
end * JOINT
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_absolute_name *args
|
210
|
+
self.class.new to_absolute(*args)
|
211
|
+
end
|
212
|
+
|
213
|
+
def nth_left n
|
214
|
+
# 1 = left; 2= left of left; 3 = left of left of left....
|
215
|
+
( n >= size ? parts[0] : parts[0..-n-1] ).to_cardname
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
#~~~~~~~~~~~~~~~~~~~~ MISC ~~~~~~~~~~~~~~~~~~~~
|
220
|
+
|
221
|
+
def replace_part oldpart, newpart
|
222
|
+
oldpart = oldpart.to_cardname
|
223
|
+
newpart = newpart.to_cardname
|
224
|
+
if oldpart.simple?
|
225
|
+
if simple?
|
226
|
+
self == oldpart ? newpart : self
|
227
|
+
else
|
228
|
+
parts.map do |p|
|
229
|
+
oldpart == p ? newpart.to_s : p
|
230
|
+
end.to_cardname
|
231
|
+
end
|
232
|
+
elsif simple?
|
233
|
+
self
|
234
|
+
else
|
235
|
+
if oldpart == parts[0, oldpart.size]
|
236
|
+
if self.size == oldpart.size
|
237
|
+
newpart
|
238
|
+
else
|
239
|
+
(newpart.parts+(parts[oldpart.size,].lines.to_a)).to_cardname
|
240
|
+
end
|
241
|
+
else
|
242
|
+
self
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.substitute! str, hash
|
248
|
+
# HACK. This doesn't belong here.
|
249
|
+
# shouldn't thus use inclusions???
|
250
|
+
hash.keys.each do |var|
|
251
|
+
str.gsub!(/\{(#{var})\}/) {|x| hash[var.to_sym]}
|
252
|
+
end
|
253
|
+
str
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirement: &10167240 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,15 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ! '>='
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0'
|
25
|
+
version_requirements: *10167240
|
31
26
|
- !ruby/object:Gem::Dependency
|
32
27
|
name: htmlentities
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
28
|
+
requirement: &10166260 !ruby/object:Gem::Requirement
|
34
29
|
none: false
|
35
30
|
requirements:
|
36
31
|
- - ~>
|
@@ -38,15 +33,10 @@ dependencies:
|
|
38
33
|
version: 4.3.0
|
39
34
|
type: :runtime
|
40
35
|
prerelease: false
|
41
|
-
version_requirements:
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 4.3.0
|
36
|
+
version_requirements: *10166260
|
47
37
|
- !ruby/object:Gem::Dependency
|
48
38
|
name: rspec
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirement: &10165120 !ruby/object:Gem::Requirement
|
50
40
|
none: false
|
51
41
|
requirements:
|
52
42
|
- - ~>
|
@@ -54,15 +44,10 @@ dependencies:
|
|
54
44
|
version: 2.8.0
|
55
45
|
type: :development
|
56
46
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 2.8.0
|
47
|
+
version_requirements: *10165120
|
63
48
|
- !ruby/object:Gem::Dependency
|
64
49
|
name: rdoc
|
65
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirement: &10164400 !ruby/object:Gem::Requirement
|
66
51
|
none: false
|
67
52
|
requirements:
|
68
53
|
- - ~>
|
@@ -70,15 +55,10 @@ dependencies:
|
|
70
55
|
version: '3.12'
|
71
56
|
type: :development
|
72
57
|
prerelease: false
|
73
|
-
version_requirements:
|
74
|
-
none: false
|
75
|
-
requirements:
|
76
|
-
- - ~>
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '3.12'
|
58
|
+
version_requirements: *10164400
|
79
59
|
- !ruby/object:Gem::Dependency
|
80
60
|
name: bundler
|
81
|
-
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirement: &10163380 !ruby/object:Gem::Requirement
|
82
62
|
none: false
|
83
63
|
requirements:
|
84
64
|
- - ~>
|
@@ -86,15 +66,10 @@ dependencies:
|
|
86
66
|
version: '1.1'
|
87
67
|
type: :development
|
88
68
|
prerelease: false
|
89
|
-
version_requirements:
|
90
|
-
none: false
|
91
|
-
requirements:
|
92
|
-
- - ~>
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '1.1'
|
69
|
+
version_requirements: *10163380
|
95
70
|
- !ruby/object:Gem::Dependency
|
96
71
|
name: jeweler
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirement: &10189020 !ruby/object:Gem::Requirement
|
98
73
|
none: false
|
99
74
|
requirements:
|
100
75
|
- - ~>
|
@@ -102,12 +77,7 @@ dependencies:
|
|
102
77
|
version: 1.8.3
|
103
78
|
type: :development
|
104
79
|
prerelease: false
|
105
|
-
version_requirements:
|
106
|
-
none: false
|
107
|
-
requirements:
|
108
|
-
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 1.8.3
|
80
|
+
version_requirements: *10189020
|
111
81
|
description: Naming patterns abstracted from the Wagn platform
|
112
82
|
email: gerryg@inbox.com
|
113
83
|
executables: []
|
@@ -120,7 +90,9 @@ files:
|
|
120
90
|
- README.rdoc
|
121
91
|
- Rakefile
|
122
92
|
- VERSION
|
93
|
+
- cardname.rb
|
123
94
|
- lib/smart_name.rb
|
95
|
+
- orig_cardname.rb
|
124
96
|
- spec/inflection_helper.rb
|
125
97
|
- spec/lib/smart_name_spec.rb
|
126
98
|
- spec/spec_helper.rb
|
@@ -143,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
115
|
version: '0'
|
144
116
|
segments:
|
145
117
|
- 0
|
146
|
-
hash:
|
118
|
+
hash: 1118870288458290680
|
147
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
120
|
none: false
|
149
121
|
requirements:
|
@@ -152,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
124
|
version: '0'
|
153
125
|
requirements: []
|
154
126
|
rubyforge_project:
|
155
|
-
rubygems_version: 1.8.
|
127
|
+
rubygems_version: 1.8.15
|
156
128
|
signing_key:
|
157
129
|
specification_version: 3
|
158
130
|
summary: Wagn names without all the wagn
|