smartname 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/lib/smart_name.rb CHANGED
@@ -194,11 +194,10 @@ class SmartName < Object
194
194
 
195
195
  #~~~~~~~~~~~~~~~~~~~~ SHOW / ABSOLUTE ~~~~~~~~~~~~~~~~~~~~
196
196
 
197
- def to_show context, args={}
198
- ignore = [ args[:ignore] ].flatten.map &:to_name
199
- fullname = parts.to_name.to_absolute_name context, args
197
+ def to_show *ignore
198
+ ignore.map! &:to_name
200
199
 
201
- show_parts = fullname.parts.map do |part|
200
+ show_parts = parts.map do |part|
202
201
  reject = ( part.empty? or part =~ /^_/ or ignore.member? part.to_name )
203
202
  reject ? nil : part
204
203
  end
@@ -206,7 +205,7 @@ class SmartName < Object
206
205
  show_name = show_parts.compact.to_name.s
207
206
 
208
207
  case
209
- when show_parts.compact.empty?; fullname
208
+ when show_parts.compact.empty?; self
210
209
  when show_parts[0].nil? ; SmartName.joint + show_name
211
210
  else show_name
212
211
  end
@@ -240,12 +240,14 @@ describe SmartName do
240
240
 
241
241
  describe "#to_show" do
242
242
  it "ignores ignorables" do
243
- 'you+awe'.to_name.to_show('A', :ignore=>'you' ).should == '+awe'
244
- 'me+you+awe'.to_name.to_show('A', :ignore=>'you' ).should == 'me+awe' #HMMM..... what should this do?
245
- 'me+you+awe'.to_name.to_show('A', :ignore=>['me','you'] ).should == '+awe'
246
- 'me+you'.to_name.to_show('A', :ignore=>['me','you'] ).should == 'me+you'
247
- '_left+_right+awe'.to_name.to_show('A+B', :ignore=>'A' ).should == '+B+awe'
248
- '?a?+awe'.to_name.to_show('B', :ignore=>'A' ).should == '+awe'
243
+ 'you+awe'.to_name.to_show('you').should == '+awe'
244
+ 'me+you+awe'.to_name.to_show('you').should == 'me+awe' #HMMM..... what should this do?
245
+ 'me+you+awe'.to_name.to_show('me' ).should == '+you+awe'
246
+ 'me+you+awe'.to_name.to_show('me','you').should == '+awe'
247
+ 'me+you'.to_name.to_show('me','you').should == 'me+you'
248
+ '?a?+awe'.to_name.to_show('A').should == '+awe'
249
+ '+awe'.to_name.to_show().should == '+awe'
250
+ '+awe'.to_name.to_show(nil).should == '+awe'
249
251
  end
250
252
  end
251
253
 
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.5
4
+ version: 0.1.6
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-12-03 00:00:00.000000000 Z
13
+ date: 2012-12-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &10167240 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *10167240
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: htmlentities
28
- requirement: &10166260 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ~>
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 4.3.0
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *10166260
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 4.3.0
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &10165120 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 2.8.0
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *10165120
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.8.0
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rdoc
50
- requirement: &10164400 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '3.12'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *10164400
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '3.12'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: bundler
61
- requirement: &10163380 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ~>
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '1.1'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *10163380
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.1'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: jeweler
72
- requirement: &10189020 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ~>
@@ -77,7 +102,12 @@ dependencies:
77
102
  version: 1.8.3
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *10189020
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.3
81
111
  description: Naming patterns abstracted from the Wagn platform
82
112
  email: gerryg@inbox.com
83
113
  executables: []
@@ -90,9 +120,7 @@ files:
90
120
  - README.rdoc
91
121
  - Rakefile
92
122
  - VERSION
93
- - cardname.rb
94
123
  - lib/smart_name.rb
95
- - orig_cardname.rb
96
124
  - spec/inflection_helper.rb
97
125
  - spec/lib/smart_name_spec.rb
98
126
  - spec/spec_helper.rb
@@ -115,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
143
  version: '0'
116
144
  segments:
117
145
  - 0
118
- hash: 1118870288458290680
146
+ hash: -4151662497955382901
119
147
  required_rubygems_version: !ruby/object:Gem::Requirement
120
148
  none: false
121
149
  requirements:
@@ -124,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
152
  version: '0'
125
153
  requirements: []
126
154
  rubyforge_project:
127
- rubygems_version: 1.8.15
155
+ rubygems_version: 1.8.24
128
156
  signing_key:
129
157
  specification_version: 3
130
158
  summary: Wagn names without all the wagn
data/cardname.rb DELETED
@@ -1,258 +0,0 @@
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/orig_cardname.rb DELETED
@@ -1,258 +0,0 @@
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
-