namelogic 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -4
- data/Gemfile.lock +6 -2
- data/VERSION +1 -1
- data/lib/name_logic.rb +33 -37
- metadata +19 -19
data/Gemfile
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
3
|
# Add dependencies to develop your gem here.
|
7
4
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -13,5 +10,5 @@ group :development do
|
|
13
10
|
#gem "rcov", ">= 0"
|
14
11
|
end
|
15
12
|
|
13
|
+
gem "activesupport"
|
16
14
|
gem 'htmlentities', '~>4.3.0'
|
17
|
-
gem 'ruby-configurable', '~>1.0.0'
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (3.2.8)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
4
7
|
diff-lcs (1.1.3)
|
5
8
|
git (1.2.5)
|
6
9
|
htmlentities (4.3.1)
|
10
|
+
i18n (0.6.1)
|
7
11
|
jeweler (1.8.3)
|
8
12
|
bundler (~> 1.0)
|
9
13
|
git (>= 1.2.5)
|
10
14
|
rake
|
11
15
|
rdoc
|
12
16
|
json (1.7.5)
|
17
|
+
multi_json (1.3.6)
|
13
18
|
rake (0.9.2.2)
|
14
19
|
rdoc (3.12)
|
15
20
|
json (~> 1.4)
|
@@ -21,15 +26,14 @@ GEM
|
|
21
26
|
rspec-expectations (2.8.0)
|
22
27
|
diff-lcs (~> 1.1.2)
|
23
28
|
rspec-mocks (2.8.0)
|
24
|
-
ruby-configurable (1.0.2)
|
25
29
|
|
26
30
|
PLATFORMS
|
27
31
|
ruby
|
28
32
|
|
29
33
|
DEPENDENCIES
|
34
|
+
activesupport
|
30
35
|
bundler (~> 1.1.0)
|
31
36
|
htmlentities (~> 4.3.0)
|
32
37
|
jeweler (~> 1.8.3)
|
33
38
|
rdoc (~> 3.12)
|
34
39
|
rspec (~> 2.8.0)
|
35
|
-
ruby-configurable (~> 1.0.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/lib/name_logic.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
require 'configurable'
|
3
|
+
require 'active_support/configurable'
|
4
4
|
require 'active_support/inflector'
|
5
5
|
|
6
6
|
class Object
|
@@ -21,25 +21,25 @@ class NameLogic < Object
|
|
21
21
|
RUBY19 = RUBY_VERSION =~ /^1\.9/
|
22
22
|
WORD_RE = RUBY19 ? '\p{Word}' : '\w'
|
23
23
|
|
24
|
-
include Configurable
|
24
|
+
include ActiveSupport::Configurable
|
25
25
|
|
26
|
-
|
27
|
-
:banned_re, :var_re, :uninflect, :params, :codes, :lookup
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
config_accessor :joint, :formal_joint, :name_attribute, :banned_array,
|
27
|
+
:banned_re, :var_re, :uninflect, :params, :codes, :lookup
|
28
|
+
|
29
|
+
NameLogic.joint = JOINT
|
30
|
+
NameLogic.formal_joint = " <span class=\"wiki-joint\">#{JOINT}</span> "
|
31
|
+
NameLogic.name_attribute = :cardname
|
32
|
+
NameLogic.banned_array = BANNED_ARRAY
|
33
|
+
NameLogic.banned_re = BANNED_RE
|
34
|
+
NameLogic.var_re = VAR_MATCH
|
35
|
+
NameLogic.uninflect = SINGULAR
|
36
36
|
|
37
37
|
@@name2nameobject = {}
|
38
38
|
|
39
39
|
class << self
|
40
40
|
def new obj
|
41
41
|
return obj if NameLogic===obj
|
42
|
-
str = Array===obj ? obj*
|
42
|
+
str = Array===obj ? obj*NameLogic.joint : obj.to_s
|
43
43
|
if known_name = @@name2nameobject[str]
|
44
44
|
known_name
|
45
45
|
else
|
@@ -53,10 +53,6 @@ class NameLogic < Object
|
|
53
53
|
# if we could make that not happen, we could avoid this (and handle spaces in urls)
|
54
54
|
uri.gsub(' ','+').gsub '_',' '
|
55
55
|
end
|
56
|
-
|
57
|
-
def joint() config.joint end
|
58
|
-
def banned_array() config.banned_array end
|
59
|
-
def banned_re() config.banned_re end
|
60
56
|
end
|
61
57
|
|
62
58
|
|
@@ -69,11 +65,11 @@ class NameLogic < Object
|
|
69
65
|
def initialize str
|
70
66
|
@s = str.to_s.strip
|
71
67
|
@s = @s.encode('UTF-8') if RUBY19
|
72
|
-
@key = if @s.index(
|
73
|
-
@parts = @s.split(/\s*#{Regexp.escape(
|
74
|
-
@parts << '' if @s[-1] ==
|
68
|
+
@key = if @s.index(NameLogic.joint)
|
69
|
+
@parts = @s.split(/\s*#{Regexp.escape(NameLogic.joint)}\s*/)
|
70
|
+
@parts << '' if @s[-1] == NameLogic.joint
|
75
71
|
@simple = false
|
76
|
-
@parts.map { |p| p.to_name.key } *
|
72
|
+
@parts.map { |p| p.to_name.key } * NameLogic.joint
|
77
73
|
else
|
78
74
|
@parts = [str]
|
79
75
|
@simple = true
|
@@ -83,7 +79,7 @@ class NameLogic < Object
|
|
83
79
|
end
|
84
80
|
|
85
81
|
def to_name() self end
|
86
|
-
def valid?() not parts.find { |pt| pt.match
|
82
|
+
def valid?() not parts.find { |pt| pt.match NameLogic.banned_re } end
|
87
83
|
def length() parts.length end
|
88
84
|
def size() to_s.size end
|
89
85
|
def blank?() s.blank? end
|
@@ -106,7 +102,7 @@ class NameLogic < Object
|
|
106
102
|
#~~~~~~~~~~~~~~~~~~~ VARIANTS ~~~~~~~~~~~~~~~~~~~
|
107
103
|
|
108
104
|
def simple_key
|
109
|
-
decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&(
|
105
|
+
decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&(NameLogic.uninflect))*'_'
|
110
106
|
end
|
111
107
|
|
112
108
|
def url_key
|
@@ -114,7 +110,7 @@ class NameLogic < Object
|
|
114
110
|
end
|
115
111
|
|
116
112
|
def safe_key
|
117
|
-
@safe_key ||= key.gsub('*','X').gsub
|
113
|
+
@safe_key ||= key.gsub('*','X').gsub NameLogic.joint, '-'
|
118
114
|
end
|
119
115
|
|
120
116
|
def decoded
|
@@ -129,7 +125,7 @@ class NameLogic < Object
|
|
129
125
|
|
130
126
|
def post_cgi
|
131
127
|
#hmm. this could resolve to the key of some other card. move to class method?
|
132
|
-
@post_cgi ||= s.gsub '~plus~',
|
128
|
+
@post_cgi ||= s.gsub '~plus~', NameLogic.joint
|
133
129
|
end
|
134
130
|
|
135
131
|
#~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
|
@@ -137,11 +133,11 @@ class NameLogic < Object
|
|
137
133
|
alias simple? simple
|
138
134
|
def junction?() not simple? end
|
139
135
|
|
140
|
-
def left() @left ||= simple? ? nil : parts[0..-2]*
|
136
|
+
def left() @left ||= simple? ? nil : parts[0..-2]*NameLogic.joint end
|
141
137
|
def right() @right ||= simple? ? nil : parts[-1] end
|
142
138
|
|
143
|
-
def left_name() @left_name ||= left &&
|
144
|
-
def right_name() @right_name ||= right &&
|
139
|
+
def left_name() @left_name ||= left && NameLogic.new( left ) end
|
140
|
+
def right_name() @right_name ||= right && NameLogic.new( right ) end
|
145
141
|
|
146
142
|
# Note that all names have a trunk and tag, but only junctions have left and right
|
147
143
|
|
@@ -169,15 +165,15 @@ class NameLogic < Object
|
|
169
165
|
junction? && begin
|
170
166
|
right_key = right_name.key
|
171
167
|
!!traitlist.find do |codename|
|
172
|
-
codecard =
|
173
|
-
codecard.send(
|
168
|
+
codecard = NameLogic.codes[ codename ] and codecard = NameLogic.lookup[ codecard ] and
|
169
|
+
codecard.send(NameLogic.name_attribute).key == right_key
|
174
170
|
end
|
175
171
|
end
|
176
172
|
end
|
177
173
|
|
178
174
|
def trait_name tag_code
|
179
|
-
codecard =
|
180
|
-
[ self, codecard.send(
|
175
|
+
codecard = NameLogic.codes[ tag_code ] and codecard = NameLogic.lookup[ codecard ] and
|
176
|
+
[ self, codecard.send(NameLogic.name_attribute) ].to_name
|
181
177
|
end
|
182
178
|
|
183
179
|
def trait tag_code
|
@@ -201,7 +197,7 @@ class NameLogic < Object
|
|
201
197
|
initial_blank = show_parts[0].nil?
|
202
198
|
show_name = show_parts.compact.to_name.s
|
203
199
|
|
204
|
-
initial_blank ?
|
200
|
+
initial_blank ? NameLogic.joint + show_name : show_name
|
205
201
|
end
|
206
202
|
|
207
203
|
|
@@ -210,7 +206,7 @@ class NameLogic < Object
|
|
210
206
|
parts.map do |part|
|
211
207
|
new_part = case part
|
212
208
|
when /^_user$/i; (user=Session.user_card) ? user.name : part
|
213
|
-
when /^_main$/i;
|
209
|
+
when /^_main$/i; NameLogic.params[:main_name]
|
214
210
|
when /^(_self|_whole|_)$/i; context.s
|
215
211
|
when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
|
216
212
|
when /^_right$/i; context.tag
|
@@ -229,11 +225,11 @@ class NameLogic < Object
|
|
229
225
|
part
|
230
226
|
end.to_s.strip
|
231
227
|
new_part.empty? ? context.to_s : new_part
|
232
|
-
end *
|
228
|
+
end * NameLogic.joint
|
233
229
|
end
|
234
230
|
|
235
231
|
def to_absolute_name *args
|
236
|
-
|
232
|
+
NameLogic.new to_absolute(*args)
|
237
233
|
end
|
238
234
|
|
239
235
|
def nth_left n
|
@@ -272,7 +268,7 @@ class NameLogic < Object
|
|
272
268
|
|
273
269
|
def self.substitute! str, hash
|
274
270
|
hash.keys.each do |var|
|
275
|
-
str.gsub!(
|
271
|
+
str.gsub!(NameLogic.var_re) { |x| (v=hash[var.to_sym]).nil? ? x : v }
|
276
272
|
end
|
277
273
|
str
|
278
274
|
end
|
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.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,30 +12,30 @@ cert_chain: []
|
|
12
12
|
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: activesupport
|
16
|
+
requirement: &9475460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9475460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: htmlentities
|
27
|
+
requirement: &9473680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9473680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &9471900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9471900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &9470640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.12'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *9470640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &9485520 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.1.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *9485520
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &9484240 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 1.8.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *9484240
|
80
80
|
description: Wiki Segmented Name Logic
|
81
81
|
email: gerryg@inbox.com
|
82
82
|
executables: []
|
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash:
|
117
|
+
hash: 1700480941420385505
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|