namelogic 0.0.11 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- == namelogic
2
+ == smartname
3
3
 
4
4
  Wiki Segmented Name Logic
5
5
 
data/Rakefile CHANGED
@@ -60,7 +60,7 @@ require 'rdoc/task'
60
60
  Rake::RDocTask.new do |rdoc|
61
61
 
62
62
  rdoc.rdoc_dir = 'rdoc'
63
- rdoc.title = "namelogic #{VERSION}"
63
+ rdoc.title = "smartname #{VERSION}"
64
64
  rdoc.rdoc_files.include('README*')
65
65
  rdoc.rdoc_files.include('lib/**/*.rb')
66
66
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.1.1
@@ -4,10 +4,10 @@ require 'active_support/configurable'
4
4
  require 'active_support/inflector'
5
5
 
6
6
  class Object
7
- def to_name() NameLogic.new(self) end
7
+ def to_name() SmartName.new(self) end
8
8
  end
9
9
 
10
- class NameLogic < Object
10
+ class SmartName < Object
11
11
  require 'htmlentities'
12
12
  RUBY19 = RUBY_VERSION =~ /^1\.9/
13
13
  WORD_RE = RUBY19 ? '\p{Word}' : '\w'
@@ -19,19 +19,19 @@ class NameLogic < Object
19
19
 
20
20
  # Wagny defaults:
21
21
  JOINT = '+'
22
- NameLogic.joint = JOINT
23
- NameLogic.formal_joint = " <span class=\"wiki-joint\">#{JOINT}</span> "
24
- NameLogic.banned_array = [ '/', '~', '|' ]
25
- NameLogic.name_attribute = :cardname
26
- NameLogic.var_re = /\{([^\}]*})\}/
27
- NameLogic.uninflect = :singularize
22
+ SmartName.joint = JOINT
23
+ SmartName.formal_joint = " <span class=\"wiki-joint\">#{JOINT}</span> "
24
+ SmartName.banned_array = [ '/', '~', '|' ]
25
+ SmartName.name_attribute = :cardname
26
+ SmartName.var_re = /\{([^\}]*})\}/
27
+ SmartName.uninflect = :singularize
28
28
 
29
29
  @@name2nameobject = {}
30
30
 
31
31
  class << self
32
32
  def new obj
33
- return obj if NameLogic===obj
34
- str = Array===obj ? obj*NameLogic.joint : obj.to_s
33
+ return obj if SmartName===obj
34
+ str = Array===obj ? obj*SmartName.joint : obj.to_s
35
35
  if known_name = @@name2nameobject[str]
36
36
  known_name
37
37
  else
@@ -47,7 +47,7 @@ class NameLogic < Object
47
47
  end
48
48
 
49
49
  def banned_re
50
- %r{#{ (['['] + NameLogic.banned_array << NameLogic.joint )*'\\' + ']' }}
50
+ %r{#{ (['['] + SmartName.banned_array << SmartName.joint )*'\\' + ']' }}
51
51
  end
52
52
  end
53
53
 
@@ -61,11 +61,11 @@ class NameLogic < Object
61
61
  def initialize str
62
62
  @s = str.to_s.strip
63
63
  @s = @s.encode('UTF-8') if RUBY19
64
- @key = if @s.index(NameLogic.joint)
65
- @parts = @s.split(/\s*#{Regexp.escape(NameLogic.joint)}\s*/)
66
- @parts << '' if @s[-1] == NameLogic.joint
64
+ @key = if @s.index(SmartName.joint)
65
+ @parts = @s.split(/\s*#{Regexp.escape(SmartName.joint)}\s*/)
66
+ @parts << '' if @s[-1] == SmartName.joint
67
67
  @simple = false
68
- @parts.map { |p| p.to_name.key } * NameLogic.joint
68
+ @parts.map { |p| p.to_name.key } * SmartName.joint
69
69
  else
70
70
  @parts = [str]
71
71
  @simple = true
@@ -75,7 +75,7 @@ class NameLogic < Object
75
75
  end
76
76
 
77
77
  def valid?()
78
- not parts.find { |pt| pt.match NameLogic.banned_re }
78
+ not parts.find { |pt| pt.match SmartName.banned_re }
79
79
  end
80
80
  def to_name() self end
81
81
  def length() parts.length end
@@ -84,7 +84,7 @@ class NameLogic < Object
84
84
  alias empty? blank?
85
85
 
86
86
  def inspect
87
- "<NameLogic key=#{key}[#{self}]>"
87
+ "<SmartName key=#{key}[#{self}]>"
88
88
  end
89
89
 
90
90
  def == obj
@@ -100,7 +100,7 @@ class NameLogic < Object
100
100
  #~~~~~~~~~~~~~~~~~~~ VARIANTS ~~~~~~~~~~~~~~~~~~~
101
101
 
102
102
  def simple_key
103
- decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&(NameLogic.uninflect))*'_'
103
+ decoded.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&(SmartName.uninflect))*'_'
104
104
  end
105
105
 
106
106
  def url_key
@@ -108,7 +108,7 @@ class NameLogic < Object
108
108
  end
109
109
 
110
110
  def safe_key
111
- @safe_key ||= key.gsub('*','X').gsub NameLogic.joint, '-'
111
+ @safe_key ||= key.gsub('*','X').gsub SmartName.joint, '-'
112
112
  end
113
113
 
114
114
  def decoded
@@ -123,7 +123,7 @@ class NameLogic < Object
123
123
 
124
124
  def post_cgi
125
125
  #hmm. this could resolve to the key of some other card. move to class method?
126
- @post_cgi ||= s.gsub '~plus~', NameLogic.joint
126
+ @post_cgi ||= s.gsub '~plus~', SmartName.joint
127
127
  end
128
128
 
129
129
  #~~~~~~~~~~~~~~~~~~~ PARTS ~~~~~~~~~~~~~~~~~~~
@@ -131,11 +131,11 @@ class NameLogic < Object
131
131
  alias simple? simple
132
132
  def junction?() not simple? end
133
133
 
134
- def left() @left ||= simple? ? nil : parts[0..-2]*NameLogic.joint end
134
+ def left() @left ||= simple? ? nil : parts[0..-2]*SmartName.joint end
135
135
  def right() @right ||= simple? ? nil : parts[-1] end
136
136
 
137
- def left_name() @left_name ||= left && NameLogic.new( left ) end
138
- def right_name() @right_name ||= right && NameLogic.new( right ) end
137
+ def left_name() @left_name ||= left && SmartName.new( left ) end
138
+ def right_name() @right_name ||= right && SmartName.new( right ) end
139
139
 
140
140
  # Note that all names have a trunk and tag, but only junctions have left and right
141
141
 
@@ -163,15 +163,15 @@ class NameLogic < Object
163
163
  junction? && begin
164
164
  right_key = right_name.key
165
165
  !!traitlist.find do |codename|
166
- codecard = NameLogic.codes[ codename ] and codecard = NameLogic.lookup[ codecard ] and
167
- codecard.send(NameLogic.name_attribute).key == right_key
166
+ codecard = SmartName.codes[ codename ] and codecard = SmartName.lookup[ codecard ] and
167
+ codecard.send(SmartName.name_attribute).key == right_key
168
168
  end
169
169
  end
170
170
  end
171
171
 
172
172
  def trait_name tag_code
173
- codecard = NameLogic.codes[ tag_code ] and codecard = NameLogic.lookup[ codecard ] and
174
- [ self, codecard.send(NameLogic.name_attribute) ].to_name
173
+ codecard = SmartName.codes[ tag_code ] and codecard = SmartName.lookup[ codecard ] and
174
+ [ self, codecard.send(SmartName.name_attribute) ].to_name
175
175
  end
176
176
 
177
177
  def trait tag_code
@@ -195,7 +195,7 @@ class NameLogic < Object
195
195
  initial_blank = show_parts[0].nil?
196
196
  show_name = show_parts.compact.to_name.s
197
197
 
198
- initial_blank ? NameLogic.joint + show_name : show_name
198
+ initial_blank ? SmartName.joint + show_name : show_name
199
199
  end
200
200
 
201
201
 
@@ -204,7 +204,7 @@ class NameLogic < Object
204
204
  parts.map do |part|
205
205
  new_part = case part
206
206
  when /^_user$/i; (user=Session.user_card) ? user.name : part
207
- when /^_main$/i; NameLogic.params[:main_name]
207
+ when /^_main$/i; SmartName.params[:main_name]
208
208
  when /^(_self|_whole|_)$/i; context.s
209
209
  when /^_left$/i; context.trunk #note - inconsistent use of left v. trunk
210
210
  when /^_right$/i; context.tag
@@ -223,11 +223,11 @@ class NameLogic < Object
223
223
  part
224
224
  end.to_s.strip
225
225
  new_part.empty? ? context.to_s : new_part
226
- end * NameLogic.joint
226
+ end * SmartName.joint
227
227
  end
228
228
 
229
229
  def to_absolute_name *args
230
- NameLogic.new to_absolute(*args)
230
+ SmartName.new to_absolute(*args)
231
231
  end
232
232
 
233
233
  def nth_left n
@@ -266,7 +266,7 @@ class NameLogic < Object
266
266
 
267
267
  def self.substitute! str, hash
268
268
  hash.keys.each do |var|
269
- str.gsub!(NameLogic.var_re) { |x| (v=hash[var.to_sym]).nil? ? x : v }
269
+ str.gsub!(SmartName.var_re) { |x| (v=hash[var.to_sym]).nil? ? x : v }
270
270
  end
271
271
  str
272
272
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
3
3
 
4
- describe NameLogic do
4
+ describe SmartName do
5
5
 
6
6
  describe "#key" do
7
7
  it "should remove spaces" do
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,14 @@
1
1
 
2
- require 'name_logic'
2
+ require 'smart_name'
3
3
  require File.expand_path('./inflection_helper', File.dirname(__FILE__))
4
4
 
5
5
  class CardMock < String
6
6
  def name() to_name end
7
7
  end
8
8
 
9
- NameLogic.name_attribute= :name
10
- NameLogic.codes= { :content => 1 }
11
- NameLogic.lookup= { 1 => CardMock.new('*content'), }
9
+ SmartName.name_attribute= :name
10
+ SmartName.codes= { :content => 1 }
11
+ SmartName.lookup= { 1 => CardMock.new('*content'), }
12
12
 
13
13
  RSpec.configure do |config|
14
14
 
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.11
4
+ version: 0.1.1
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-27 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &9718440 !ruby/object:Gem::Requirement
16
+ requirement: &5308300 !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: *9718440
24
+ version_requirements: *5308300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: htmlentities
27
- requirement: &9717180 !ruby/object:Gem::Requirement
27
+ requirement: &5305220 !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: *9717180
35
+ version_requirements: *5305220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &9716100 !ruby/object:Gem::Requirement
38
+ requirement: &5320400 !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: *9716100
46
+ version_requirements: *5320400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &9730920 !ruby/object:Gem::Requirement
49
+ requirement: &5319080 !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: *9730920
57
+ version_requirements: *5319080
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &9729040 !ruby/object:Gem::Requirement
60
+ requirement: &5317820 !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: *9729040
68
+ version_requirements: *5317820
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &9727380 !ruby/object:Gem::Requirement
71
+ requirement: &5316700 !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: *9727380
79
+ version_requirements: *5316700
80
80
  description: Wiki Segmented Name Logic
81
81
  email: gerryg@inbox.com
82
82
  executables: []
@@ -89,9 +89,9 @@ files:
89
89
  - README.rdoc
90
90
  - Rakefile
91
91
  - VERSION
92
- - lib/name_logic.rb
92
+ - lib/smart_name.rb
93
93
  - spec/inflection_helper.rb
94
- - spec/lib/name_logic_spec.rb
94
+ - spec/lib/smart_name_spec.rb
95
95
  - spec/spec_helper.rb
96
96
  - test.rb
97
97
  - test2.rb
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: 1344875529140872551
117
+ hash: -4244501553404561950
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements: