namelogic 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -9,30 +9,22 @@ end
9
9
 
10
10
  class NameLogic < Object
11
11
  require 'htmlentities'
12
-
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'
12
+ RUBY19 = RUBY_VERSION =~ /^1\.9/
13
+ WORD_RE = RUBY19 ? '\p{Word}' : '\w'
23
14
 
24
15
  include ActiveSupport::Configurable
25
16
 
26
17
  config_accessor :joint, :formal_joint, :name_attribute, :banned_array,
27
- :banned_re, :var_re, :uninflect, :params, :codes, :lookup
18
+ :var_re, :uninflect, :params, :codes, :lookup
28
19
 
20
+ # Wagny defaults:
21
+ JOINT = '+'
29
22
  NameLogic.joint = JOINT
30
23
  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
24
+ NameLogic.banned_array = [ '/', '~', '|' ]
25
+ NameLogic.name_attribute = :cardname
26
+ NameLogic.var_re = /\{([^\}]*})\}/
27
+ NameLogic.uninflect = :singularize
36
28
 
37
29
  @@name2nameobject = {}
38
30
 
@@ -53,6 +45,10 @@ class NameLogic < Object
53
45
  # if we could make that not happen, we could avoid this (and handle spaces in urls)
54
46
  uri.gsub(' ','+').gsub '_',' '
55
47
  end
48
+
49
+ def banned_re
50
+ %r{#{ (['['] + NameLogic.banned_array << NameLogic.joint )*'\\' + ']' }}
51
+ end
56
52
  end
57
53
 
58
54
 
@@ -78,11 +74,13 @@ class NameLogic < Object
78
74
  @@name2nameobject[str] = self
79
75
  end
80
76
 
81
- def to_name() self end
82
- def valid?() not parts.find { |pt| pt.match NameLogic.banned_re } end
83
- def length() parts.length end
84
- def size() to_s.size end
85
- def blank?() s.blank? end
77
+ def valid?()
78
+ not parts.find { |pt| pt.match NameLogic.banned_re }
79
+ end
80
+ def to_name() self end
81
+ def length() parts.length end
82
+ def size() to_s.size end
83
+ def blank?() s.blank? end
86
84
  alias empty? blank?
87
85
 
88
86
  def inspect
@@ -131,21 +129,21 @@ class NameLogic < Object
131
129
  #~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
132
130
 
133
131
  alias simple? simple
134
- def junction?() not simple? end
132
+ def junction?() not simple? end
135
133
 
136
- def left() @left ||= simple? ? nil : parts[0..-2]*NameLogic.joint end
137
- def right() @right ||= simple? ? nil : parts[-1] end
134
+ def left() @left ||= simple? ? nil : parts[0..-2]*NameLogic.joint end
135
+ def right() @right ||= simple? ? nil : parts[-1] end
138
136
 
139
- def left_name() @left_name ||= left && NameLogic.new( left ) end
140
- def right_name() @right_name ||= right && NameLogic.new( right ) end
137
+ def left_name() @left_name ||= left && NameLogic.new( left ) end
138
+ def right_name() @right_name ||= right && NameLogic.new( right ) end
141
139
 
142
140
  # Note that all names have a trunk and tag, but only junctions have left and right
143
141
 
144
- def trunk() @trunk ||= simple? ? s : left end
145
- def tag() @tag ||= simple? ? s : right end
142
+ def trunk() @trunk ||= simple? ? s : left end
143
+ def tag() @tag ||= simple? ? s : right end
146
144
 
147
- def trunk_name() @trunk_name ||= simple? ? self : left_name end
148
- def tag_name() @tag_name ||= simple? ? self : right_name end
145
+ def trunk_name() @trunk_name ||= simple? ? self : left_name end
146
+ def tag_name() @tag_name ||= simple? ? self : right_name end
149
147
 
150
148
  def pieces
151
149
  @pieces ||= if simple?
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Add new inflection rules using the following format
3
+ # Add new inflection rules using the following format
4
4
  ActiveSupport::Inflector.inflections do |inflect|
5
5
  inflect.irregular 'grave', 'graveyard'
6
6
  inflect.uncountable 'this'
@@ -2,57 +2,57 @@
2
2
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
3
3
 
4
4
  describe NameLogic do
5
-
5
+
6
6
  describe "#key" do
7
7
  it "should remove spaces" do
8
8
  "this Name".to_name.key.should == "this_name"
9
9
  end
10
-
10
+
11
11
  it "should have initial _ for initial cap" do
12
12
  "This Name".to_name.key.should == "this_name"
13
13
  end
14
-
14
+
15
15
  it "should have initial _ for initial cap" do
16
16
  "_This Name".to_name.key.should == "this_name"
17
17
  end
18
-
18
+
19
19
  it "should singularize" do
20
20
  "ethans".to_name.key.should == "ethan"
21
- end
22
-
23
- it "should underscore" do
21
+ end
22
+
23
+ it "should underscore" do
24
24
  "ThisThing".to_name.key.should == "this_thing"
25
25
  end
26
-
26
+
27
27
  it "should handle plus cards" do
28
28
  "ThisThing+Ethans".to_name.key.should == "this_thing+ethan"
29
- end
30
-
29
+ end
30
+
31
31
  it "should retain * for star cards" do
32
32
  "*right".to_name.key.should == "*right"
33
33
  end
34
-
34
+
35
35
  it "should not singularize double s's" do
36
- "grass".to_name.key.should == 'grass'
36
+ "grass".to_name.key.should == 'grass'
37
37
  end
38
-
38
+
39
39
  it "should not singularize letter 'S'" do
40
40
  'S'.to_name.key.should == 's'
41
41
  end
42
-
42
+
43
43
  it "should handle unicode characters" do
44
44
  "Mañana".to_name.key.should == 'mañana'
45
45
  end
46
-
46
+
47
47
  it "should handle weird initial characters" do
48
48
  '__you motha @#$'.to_name.key.should == 'you_motha'
49
49
  '?!_you motha @#$'.to_name.key.should == 'you_motha'
50
50
  end
51
-
51
+
52
52
  it "should allow numbers" do
53
53
  "3way".to_name.key.should == '3way'
54
54
  end
55
-
55
+
56
56
  it "internal plurals" do
57
57
  "cards hooks label foos".to_name.key.should == 'card_hook_label_foo'
58
58
  end
@@ -62,40 +62,40 @@ describe NameLogic do
62
62
  "Jean-fran&ccedil;ois Noubel".to_name.key.should == 'jean_françoi_noubel'
63
63
  end
64
64
  end
65
-
66
65
 
67
-
66
+
67
+
68
68
 
69
69
 
70
70
  describe "#url_key" do
71
71
  cardnames = ["GrassCommons.org", 'Oh you @##', "Alice's Restaurant!", "PB &amp; J", "Mañana"].map(&:to_name)
72
-
73
- cardnames.each do |cardname|
72
+
73
+ cardnames.each do |cardname|
74
74
  it "should have the same key as the name" do
75
75
  k, k2 = cardname.key, cardname.url_key
76
76
  #warn "cn tok #{cardname.inspect}, #{k.inspect}, #{k2.inspect}"
77
77
  k.should == k2.to_name.key
78
78
  end
79
79
  end
80
- end
80
+ end
81
81
 
82
82
  describe "#valid" do
83
83
  it "accepts valid names" do
84
84
  "this+THAT".to_name.should be_valid
85
85
  "THE*ONE*AND$!ONLY".to_name.should be_valid
86
- end
87
-
86
+ end
87
+
88
88
  it "rejects invalide names" do
89
89
  "Tes~sd".to_name.should_not be_valid
90
90
  "TEST/DDER".to_name.should_not be_valid
91
91
  end
92
- end
93
-
92
+ end
93
+
94
94
  describe "#left_name" do
95
95
  it "returns nil for non junction" do
96
96
  "a".to_name.left_name.should == nil
97
97
  end
98
-
98
+
99
99
  it "returns parent for parent" do
100
100
  "a+b+c+d".to_name.left_name.should == "a+b+c"
101
101
  end
@@ -103,9 +103,9 @@ describe NameLogic do
103
103
 
104
104
  describe "#tag_name" do
105
105
  it "returns last part of plus card" do
106
- "a+b+c".to_name.tag.should == "c"
106
+ "a+b+c".to_name.tag.should == "c"
107
107
  end
108
-
108
+
109
109
  it "returns name of simple card" do
110
110
  "a".to_name.tag.should == "a"
111
111
  end
@@ -130,7 +130,7 @@ describe NameLogic do
130
130
  it "doesn't replace two part tag" do
131
131
  'a+b+c'.to_name.replace_part('b+c','x').to_s.should == 'a+b+c'
132
132
  end
133
- end
133
+ end
134
134
 
135
135
  describe "Cardnames star handling" do
136
136
  it "recognizes star cards" do
@@ -153,7 +153,7 @@ describe NameLogic do
153
153
  '*a+a'.to_name.rstar?.should be_false
154
154
  end
155
155
  end
156
-
156
+
157
157
  describe "trait_name?" do
158
158
  it "returns true for content codename" do
159
159
  "bazoinga+*right+*content".to_name.trait_name?(:content).should be_true
@@ -162,19 +162,19 @@ describe NameLogic do
162
162
  it "handles arrays" do
163
163
  "bazoinga+*right+*content".to_name.trait_name?(:content, :default).should be_true
164
164
  end
165
-
165
+
166
166
  it "returns false for non-template" do
167
167
  "bazoinga+*right+nontent".to_name.trait_name?(:content).should be_false
168
168
  end
169
169
  end
170
-
170
+
171
171
  describe "#to_absolute" do
172
172
  it "handles _self, _whole, _" do
173
173
  "_self".to_name.to_absolute("foo").should == "foo"
174
174
  "_whole".to_name.to_absolute("foo").should == "foo"
175
175
  "_".to_name.to_absolute("foo").should == "foo"
176
176
  end
177
-
177
+
178
178
  it "handles _left" do
179
179
  "_left+Z".to_name.to_absolute("A+B+C").should == "A+B+Z"
180
180
  end
@@ -182,20 +182,20 @@ describe NameLogic do
182
182
  it "handles white space" do
183
183
  "_left + Z".to_name.to_absolute("A+B+C").should == "A+B+Z"
184
184
  end
185
-
185
+
186
186
  it "handles _right" do
187
187
  "_right+bang".to_name.to_absolute("nutter+butter").should == "butter+bang"
188
188
  "C+_right".to_name.to_absolute("B+A").should == "C+A"
189
189
  end
190
-
190
+
191
191
  it "handles leading +" do
192
192
  "+bug".to_name.to_absolute("hum").should == "hum+bug"
193
193
  end
194
-
194
+
195
195
  it "handles trailing +" do
196
196
  "bug+".to_name.to_absolute("tracks").should == "bug+tracks"
197
197
  end
198
-
198
+
199
199
  it "handles _(numbers)" do
200
200
  "_1".to_name.to_absolute("A+B+C").should == "A"
201
201
  "_1+_2".to_name.to_absolute("A+B+C").should == "A+B"
@@ -212,7 +212,7 @@ describe NameLogic do
212
212
  "_LLLR".to_name.to_absolute("A+B+C+D+E").should == "B"
213
213
  "_LLLL".to_name.to_absolute("A+B+C+D+E").should == "A"
214
214
  end
215
-
215
+
216
216
  context "mismatched requests" do
217
217
  it "returns _self for _left or _right on simple cards" do
218
218
  "_left+Z".to_name.to_absolute("A").should == "A+Z"
@@ -224,7 +224,7 @@ describe NameLogic do
224
224
  "_1+_2".to_name.to_absolute("A").should == "A+A"
225
225
  "_2+_3".to_name.to_absolute("A").should == "A+A"
226
226
  end
227
-
227
+
228
228
  it "handles bogus _llr requests" do
229
229
  "_R".to_name.to_absolute("A").should == "A"
230
230
  "_L".to_name.to_absolute("A").should == "A"
@@ -237,7 +237,7 @@ describe NameLogic do
237
237
  end
238
238
  end
239
239
  end
240
-
240
+
241
241
  describe "#to_show" do
242
242
  it "ignores ignorables" do
243
243
  'you+awe'.to_name.to_show('A', :ignore=>'you' ).should == '+awe'
@@ -247,5 +247,5 @@ describe NameLogic do
247
247
  '?a?+awe'.to_name.to_show('B', :ignore=>'A' ).should == '+awe'
248
248
  end
249
249
  end
250
-
250
+
251
251
  end
@@ -6,24 +6,18 @@ class CardMock < String
6
6
  def name() to_name end
7
7
  end
8
8
 
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
9
+ NameLogic.name_attribute= :name
10
+ NameLogic.codes= { :content => 1 }
11
+ NameLogic.lookup= { 1 => CardMock.new('*content'), }
18
12
 
19
13
  RSpec.configure do |config|
20
-
14
+
21
15
  #config.include CustomMatchers
22
16
  #config.include ControllerMacros, :type=>:controllers
23
17
  #config.include AuthenticatedTestHelper, :type=>:controllers
24
18
  #config.include(EmailSpec::Helpers)
25
19
  #config.include(EmailSpec::Matchers)
26
-
20
+
27
21
  # == Mock Framework
28
22
  # If you prefer to mock with mocha, flexmock or RR, uncomment the appropriate symbol:
29
23
  # :mocha, :flexmock, :rr
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.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &9475460 !ruby/object:Gem::Requirement
16
+ requirement: &9718440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9475460
24
+ version_requirements: *9718440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: htmlentities
27
- requirement: &9473680 !ruby/object:Gem::Requirement
27
+ requirement: &9717180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9473680
35
+ version_requirements: *9717180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &9471900 !ruby/object:Gem::Requirement
38
+ requirement: &9716100 !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: *9471900
46
+ version_requirements: *9716100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &9470640 !ruby/object:Gem::Requirement
49
+ requirement: &9730920 !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: *9470640
57
+ version_requirements: *9730920
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &9485520 !ruby/object:Gem::Requirement
60
+ requirement: &9729040 !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: *9485520
68
+ version_requirements: *9729040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &9484240 !ruby/object:Gem::Requirement
71
+ requirement: &9727380 !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: *9484240
79
+ version_requirements: *9727380
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: 1700480941420385505
117
+ hash: 1344875529140872551
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements: