namelogic 0.0.8 → 0.0.9
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.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/VERSION +1 -1
- data/lib/name_logic.rb +45 -56
- data/spec/spec_helper.rb +9 -3
- metadata +24 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -21,6 +21,7 @@ GEM
|
|
21
21
|
rspec-expectations (2.8.0)
|
22
22
|
diff-lcs (~> 1.1.2)
|
23
23
|
rspec-mocks (2.8.0)
|
24
|
+
ruby-configurable (1.0.2)
|
24
25
|
|
25
26
|
PLATFORMS
|
26
27
|
ruby
|
@@ -31,3 +32,4 @@ DEPENDENCIES
|
|
31
32
|
jeweler (~> 1.8.3)
|
32
33
|
rdoc (~> 3.12)
|
33
34
|
rspec (~> 2.8.0)
|
35
|
+
ruby-configurable (~> 1.0.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/lib/name_logic.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
+
require 'configurable'
|
3
4
|
require 'active_support/inflector'
|
4
5
|
|
5
6
|
class Object
|
@@ -9,35 +10,36 @@ end
|
|
9
10
|
class NameLogic < Object
|
10
11
|
require 'htmlentities'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
13
|
+
# Wagny defaults
|
14
|
+
JOINT = '+'
|
15
|
+
BANNED_ARRAY = [ '/', '~', '|' ]
|
16
|
+
BANNED_RE = /#{ (['['] + BANNED_ARRAY << JOINT )*'\\' + ']' }/
|
17
|
+
BANNED_CHARACTERS = BANNED_ARRAY * ' '
|
18
|
+
VAR_MATCH = /\{([^\}]*})\}/
|
19
|
+
SINGULAR = :singularize
|
20
|
+
|
21
|
+
RUBY19 = RUBY_VERSION =~ /^1\.9/
|
22
|
+
WORD_RE = RUBY19 ? '\p{Word}' : '\w'
|
23
|
+
|
24
|
+
include Configurable
|
25
|
+
|
26
|
+
configurable_options :joint, :formal_joint, :name_attribute, :banned_array,
|
27
|
+
:banned_re, :var_re, :uninflect, :params, :codes, :lookup,
|
28
|
+
:joint => JOINT,
|
29
|
+
:formal_joint => " <span class=\"wiki-joint\">#{JOINT}</span> ",
|
30
|
+
:name_attribute => :cardname,
|
31
|
+
:banned_array => BANNED_ARRAY,
|
32
|
+
:banned_re => BANNED_RE,
|
33
|
+
#BANNED_RE = /#{ (['['] + BANNED_ARRAY << JOINT )*'\\' }#{ ']' }/,
|
34
|
+
:var_re => VAR_MATCH,
|
35
|
+
:uninflect => SINGULAR
|
34
36
|
|
35
37
|
@@name2nameobject = {}
|
36
38
|
|
37
39
|
class << self
|
38
40
|
def new obj
|
39
41
|
return obj if NameLogic===obj
|
40
|
-
str = Array===obj ? obj
|
42
|
+
str = Array===obj ? obj*config.joint : obj.to_s
|
41
43
|
if known_name = @@name2nameobject[str]
|
42
44
|
known_name
|
43
45
|
else
|
@@ -52,21 +54,9 @@ class NameLogic < Object
|
|
52
54
|
uri.gsub(' ','+').gsub '_',' '
|
53
55
|
end
|
54
56
|
|
55
|
-
|
56
|
-
def
|
57
|
-
def
|
58
|
-
def formal_joint() @@formal_joint end
|
59
|
-
def formal_joint=(v) @@formal_joint = v end
|
60
|
-
def banned_array() @@banned_array end
|
61
|
-
def banned_array=(v) @@banned_array = v end
|
62
|
-
def banned_re() @@banned_re end
|
63
|
-
def banned_re=(v) @@banned_re = v end
|
64
|
-
def var_match=(v) @@var_match = v end
|
65
|
-
def uninflect=(v) @@uninflect = v end
|
66
|
-
def name_attribute=(v) @@name_attribute = v end
|
67
|
-
def main_hash=(v) @@main_hash = v end
|
68
|
-
def code_hash=(v) @@code_hash = v end
|
69
|
-
def fetch=(v) @@fetch = v end
|
57
|
+
def joint() config.joint end
|
58
|
+
def banned_array() config.banned_array end
|
59
|
+
def banned_re() config.banned_re end
|
70
60
|
end
|
71
61
|
|
72
62
|
|
@@ -79,11 +69,11 @@ class NameLogic < Object
|
|
79
69
|
def initialize str
|
80
70
|
@s = str.to_s.strip
|
81
71
|
@s = @s.encode('UTF-8') if RUBY19
|
82
|
-
@key = if @s.index(
|
83
|
-
@parts = @s.split(/\s*#{Regexp.escape(
|
84
|
-
@parts << '' if @s[-1] ==
|
72
|
+
@key = if @s.index(config.joint)
|
73
|
+
@parts = @s.split(/\s*#{Regexp.escape(config.joint)}\s*/)
|
74
|
+
@parts << '' if @s[-1] == config.joint
|
85
75
|
@simple = false
|
86
|
-
@parts.map { |p| p.to_name.key } *
|
76
|
+
@parts.map { |p| p.to_name.key } * config.joint
|
87
77
|
else
|
88
78
|
@parts = [str]
|
89
79
|
@simple = true
|
@@ -93,7 +83,7 @@ class NameLogic < Object
|
|
93
83
|
end
|
94
84
|
|
95
85
|
def to_name() self end
|
96
|
-
def valid?() not parts.find { |pt| pt.match
|
86
|
+
def valid?() not parts.find { |pt| pt.match config.banned_re } end
|
97
87
|
def length() parts.length end
|
98
88
|
def size() to_s.size end
|
99
89
|
def blank?() s.blank? end
|
@@ -116,7 +106,7 @@ class NameLogic < Object
|
|
116
106
|
#~~~~~~~~~~~~~~~~~~~ VARIANTS ~~~~~~~~~~~~~~~~~~~
|
117
107
|
|
118
108
|
def simple_key
|
119
|
-
decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(
|
109
|
+
decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&(config.uninflect))*'_'
|
120
110
|
end
|
121
111
|
|
122
112
|
def url_key
|
@@ -124,7 +114,7 @@ class NameLogic < Object
|
|
124
114
|
end
|
125
115
|
|
126
116
|
def safe_key
|
127
|
-
@safe_key ||= key.gsub('*','X').gsub
|
117
|
+
@safe_key ||= key.gsub('*','X').gsub config.joint, '-'
|
128
118
|
end
|
129
119
|
|
130
120
|
def decoded
|
@@ -139,7 +129,7 @@ class NameLogic < Object
|
|
139
129
|
|
140
130
|
def post_cgi
|
141
131
|
#hmm. this could resolve to the key of some other card. move to class method?
|
142
|
-
@post_cgi ||= s.gsub '~plus~',
|
132
|
+
@post_cgi ||= s.gsub '~plus~', config.joint
|
143
133
|
end
|
144
134
|
|
145
135
|
#~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
|
@@ -147,7 +137,7 @@ class NameLogic < Object
|
|
147
137
|
alias simple? simple
|
148
138
|
def junction?() not simple? end
|
149
139
|
|
150
|
-
def left() @left ||= simple? ? nil : parts[0..-2]
|
140
|
+
def left() @left ||= simple? ? nil : parts[0..-2]*config.joint end
|
151
141
|
def right() @right ||= simple? ? nil : parts[-1] end
|
152
142
|
|
153
143
|
def left_name() @left_name ||= left && self.class.new( left ) end
|
@@ -179,16 +169,15 @@ class NameLogic < Object
|
|
179
169
|
junction? && begin
|
180
170
|
right_key = right_name.key
|
181
171
|
!!traitlist.find do |codename|
|
182
|
-
|
183
|
-
|
184
|
-
codecard.send(@@name_attribute).key == right_key
|
172
|
+
codecard = config.codes[ codename ] and codecard = config.lookup[ codecard ] and
|
173
|
+
codecard.send(config.name_attribute).key == right_key
|
185
174
|
end
|
186
175
|
end
|
187
176
|
end
|
188
177
|
|
189
178
|
def trait_name tag_code
|
190
|
-
codecard =
|
191
|
-
[ self, codecard.send(
|
179
|
+
codecard = config.codes[ tag_code ] and codecard = config.lookup[ codecard ] and
|
180
|
+
[ self, codecard.send(config.name_attribute) ].to_name
|
192
181
|
end
|
193
182
|
|
194
183
|
def trait tag_code
|
@@ -212,7 +201,7 @@ class NameLogic < Object
|
|
212
201
|
initial_blank = show_parts[0].nil?
|
213
202
|
show_name = show_parts.compact.to_name.s
|
214
203
|
|
215
|
-
initial_blank ?
|
204
|
+
initial_blank ? config.joint + show_name : show_name
|
216
205
|
end
|
217
206
|
|
218
207
|
|
@@ -221,7 +210,7 @@ class NameLogic < Object
|
|
221
210
|
parts.map do |part|
|
222
211
|
new_part = case part
|
223
212
|
when /^_user$/i; (user=Session.user_card) ? user.name : part
|
224
|
-
when /^_main$/i;
|
213
|
+
when /^_main$/i; config.params[:main_name]
|
225
214
|
when /^(_self|_whole|_)$/i; context.s
|
226
215
|
when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
|
227
216
|
when /^_right$/i; context.tag
|
@@ -240,7 +229,7 @@ class NameLogic < Object
|
|
240
229
|
part
|
241
230
|
end.to_s.strip
|
242
231
|
new_part.empty? ? context.to_s : new_part
|
243
|
-
end *
|
232
|
+
end * config.joint
|
244
233
|
end
|
245
234
|
|
246
235
|
def to_absolute_name *args
|
@@ -283,7 +272,7 @@ class NameLogic < Object
|
|
283
272
|
|
284
273
|
def self.substitute! str, hash
|
285
274
|
hash.keys.each do |var|
|
286
|
-
str.gsub!(
|
275
|
+
str.gsub!(config.var_re) { |x| (v=hash[var.to_sym]).nil? ? x : v }
|
287
276
|
end
|
288
277
|
str
|
289
278
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,15 @@ class CardMock < String
|
|
6
6
|
def name() to_name end
|
7
7
|
end
|
8
8
|
|
9
|
-
NameLogic.name_attribute= :name
|
10
|
-
NameLogic.
|
11
|
-
NameLogic.
|
9
|
+
NameLogic.config.name_attribute= :name
|
10
|
+
NameLogic.config.codes= { :content => 1 }
|
11
|
+
NameLogic.config.lookup= { 1 => CardMock.new('*content'), }
|
12
|
+
|
13
|
+
#NameLogic.configure do |config|
|
14
|
+
#name_attribute= :name
|
15
|
+
#codes= { :content => 1 }
|
16
|
+
#lookup= { 1 => CardMock.new('*content'), }
|
17
|
+
#end
|
12
18
|
|
13
19
|
RSpec.configure do |config|
|
14
20
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: namelogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: htmlentities
|
16
|
-
requirement: &
|
16
|
+
requirement: &9199420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: 4.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9199420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-configurable
|
27
|
+
requirement: &9198820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *9198820
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &9198020 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ~>
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: 2.8.0
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *9198020
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rdoc
|
38
|
-
requirement: &
|
49
|
+
requirement: &9197340 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '3.12'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *9197340
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: bundler
|
49
|
-
requirement: &
|
60
|
+
requirement: &9196700 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 1.1.0
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *9196700
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: jeweler
|
60
|
-
requirement: &
|
71
|
+
requirement: &9196040 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,7 +76,7 @@ dependencies:
|
|
65
76
|
version: 1.8.3
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *9196040
|
69
80
|
description: Wiki Segmented Name Logic
|
70
81
|
email: gerryg@inbox.com
|
71
82
|
executables: []
|
@@ -103,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
114
|
version: '0'
|
104
115
|
segments:
|
105
116
|
- 0
|
106
|
-
hash:
|
117
|
+
hash: -2071270473877385600
|
107
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
119
|
none: false
|
109
120
|
requirements:
|