namelogic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +17 -0
- data/Gemfile.lock +37 -0
- data/README.rdoc +7 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/lib/name_logic.rb +193 -0
- data/spec/lib/name_logic_spec.rb +194 -0
- data/spec/spec_helper.rb +15 -0
- data/test.rb +14 -0
- data/test2.rb +12 -0
- metadata +129 -0
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.1.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
#gem "rcov", ">= 0"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'htmlentities', '~>4.3.0'
|
17
|
+
gem 'active_support'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
active_support (3.0.0)
|
5
|
+
activesupport (= 3.0.0)
|
6
|
+
activesupport (3.0.0)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
git (1.2.5)
|
9
|
+
htmlentities (4.3.1)
|
10
|
+
jeweler (1.8.3)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
rdoc
|
15
|
+
json (1.6.5)
|
16
|
+
rake (0.9.2.2)
|
17
|
+
rdoc (3.12)
|
18
|
+
json (~> 1.4)
|
19
|
+
rspec (2.8.0)
|
20
|
+
rspec-core (~> 2.8.0)
|
21
|
+
rspec-expectations (~> 2.8.0)
|
22
|
+
rspec-mocks (~> 2.8.0)
|
23
|
+
rspec-core (2.8.0)
|
24
|
+
rspec-expectations (2.8.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.8.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
active_support
|
33
|
+
bundler (~> 1.1.0)
|
34
|
+
htmlentities (~> 4.3.0)
|
35
|
+
jeweler (~> 1.8.3)
|
36
|
+
rdoc (~> 3.12)
|
37
|
+
rspec (~> 2.8.0)
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
VERSION = File.exist?('VERSION') ? File.read('VERSION') : ""
|
8
|
+
|
9
|
+
begin
|
10
|
+
Bundler.setup(:default, :development)
|
11
|
+
rescue Bundler::BundlerError => e
|
12
|
+
$stderr.puts e.message
|
13
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
14
|
+
exit e.status_code
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rake'
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'jeweler'
|
21
|
+
Jeweler::Tasks.new do |gem|
|
22
|
+
gem.name = 'namelogic'
|
23
|
+
gem.version = VERSION
|
24
|
+
gem.license = "MIT"
|
25
|
+
gem.summary = "Wiki Segmented Name Logic"
|
26
|
+
gem.email = "gerryg@inbox.com"
|
27
|
+
gem.homepage = "http://github.com/GerryG/namelogic/"
|
28
|
+
gem.description = "Wiki Segmented Name Logic"
|
29
|
+
gem.authors = ["Gerry Gleason <gerryg@inbox.com>"]
|
30
|
+
gem.files = FileList[
|
31
|
+
'[A-Z]*',
|
32
|
+
'*.rb',
|
33
|
+
'lib/**/*.rb',
|
34
|
+
'spec/**/*.rb' ].to_a
|
35
|
+
gem.test_files = Dir.glob('spec/*_spec.rb')
|
36
|
+
gem.has_rdoc = true
|
37
|
+
gem.extra_rdoc_files = [ "README.rdoc", "CHANGES" ]
|
38
|
+
gem.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
42
|
+
end
|
43
|
+
|
44
|
+
Jeweler::RubygemsDotOrgTasks.new
|
45
|
+
|
46
|
+
require 'rspec/core'
|
47
|
+
require 'rspec/core/rake_task'
|
48
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
49
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
50
|
+
end
|
51
|
+
|
52
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
53
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
54
|
+
spec.rcov = true
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :spec
|
58
|
+
|
59
|
+
require 'rdoc/task'
|
60
|
+
Rake::RDocTask.new do |rdoc|
|
61
|
+
|
62
|
+
rdoc.rdoc_dir = 'rdoc'
|
63
|
+
rdoc.title = "namelogic #{VERSION}"
|
64
|
+
rdoc.rdoc_files.include('README*')
|
65
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
66
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/name_logic.rb
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class NameLogic < String
|
3
|
+
|
4
|
+
# do: Object.send :include, NameLogic::ObjectMethods to enable x.to_name
|
5
|
+
module ObjectMethods
|
6
|
+
def to_name() NameLogic.new(self) end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'htmlentities'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :joint, :banned_array, :banned_re, :var_match,
|
13
|
+
:formal_joint, :uninflect, :name2nameobject
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing meth, *args
|
17
|
+
if self.class.respond_to? meth
|
18
|
+
self.class.send meth, *args
|
19
|
+
else raise end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Wagny defaults
|
24
|
+
JOINT = ?+
|
25
|
+
BANNED_ARRAY = [ ?/, ?~, ?| ]
|
26
|
+
BANNED_CHARACTERS = BANNED_ARRAY * ' '
|
27
|
+
|
28
|
+
VAR_MATCH = /\{([^\}]*})\}/
|
29
|
+
WORD_RE = RUBY_VERSION =~ /^1\.9/ ? '\p{Word}/' : '/\w/'
|
30
|
+
SINGULAR = :singularize
|
31
|
+
|
32
|
+
@name2nameobject = {}
|
33
|
+
|
34
|
+
# reset these class instance vars to your system's to customize name syntax
|
35
|
+
@joint = JOINT
|
36
|
+
@formal_joint = " <span class=\"wiki-joint\">#{JOINT}</span> "
|
37
|
+
@banned_array = BANNED_ARRAY
|
38
|
+
@banned_re = /#{ ([?[] + @banned_array << @joint )*?\\ }#{ ?] }/
|
39
|
+
@var_match = VAR_MATCH
|
40
|
+
@uninflect = SINGULAR
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def new obj
|
44
|
+
return obj if NameLogic===obj
|
45
|
+
str = Array===obj ? obj*joint : obj.to_s
|
46
|
+
return obj if obj = name2nameobject[str]
|
47
|
+
super str.strip
|
48
|
+
end
|
49
|
+
|
50
|
+
def user() '' end # override to fetch your user string for _user subs
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_reader :simple, :parts, :key
|
54
|
+
alias to_key key
|
55
|
+
|
56
|
+
def initialize str
|
57
|
+
super str
|
58
|
+
#warn "init #{str.inspect}, #{inspect}, #{self.class.joint}, #{joint}"
|
59
|
+
@key = if index joint
|
60
|
+
@parts = str.split(/\s*#{Regexp.escape(joint)}\s*/)
|
61
|
+
@parts << '' if str[-1] == joint
|
62
|
+
@simple = false
|
63
|
+
@parts.map{|p| p.to_name.key } * joint
|
64
|
+
else
|
65
|
+
@parts = [str]
|
66
|
+
@simple = true
|
67
|
+
empty? ? '' : generate_simple_key
|
68
|
+
end
|
69
|
+
name2nameobject[str] = self
|
70
|
+
end
|
71
|
+
|
72
|
+
def generate_simple_key
|
73
|
+
decode_html.underscore.gsub(/[^#{WORD_RE}\*]+/,'_').split(/_+/).reject(&:empty?).map(&uninflect)*?_
|
74
|
+
end
|
75
|
+
|
76
|
+
def decode_html
|
77
|
+
@decoded ||= (index(?&) ? HTMLEntities.new.decode(to_s) : to_s)
|
78
|
+
end
|
79
|
+
|
80
|
+
alias simple? simple
|
81
|
+
|
82
|
+
def inspect() "<Name key=#{key}[#{self}, #{parts ? parts.size : 'no size'}]>" end
|
83
|
+
|
84
|
+
def self.unescape(uri) uri.gsub(' ','+').gsub('_',' ') end
|
85
|
+
|
86
|
+
def self.substitute!( str, hash )
|
87
|
+
str.gsub!(var_match) { |x| (v=hash[var.to_sym]).nil? ? x : v }
|
88
|
+
str
|
89
|
+
end
|
90
|
+
|
91
|
+
def ==(obj)
|
92
|
+
obj.nil? ? false :
|
93
|
+
key == (obj.respond_to?(:to_key) ? obj.to_key :
|
94
|
+
obj.respond_to?(:to_name) ? obj.to_name.key : obj.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
def size() parts.size end
|
98
|
+
def to_name() self end
|
99
|
+
def valid?() not parts.find {|pt| pt.match(banned_re)} end
|
100
|
+
|
101
|
+
def replace_part( oldpart, newpart )
|
102
|
+
oldpart = oldpart.to_name unless NameLogic===oldpart
|
103
|
+
newpart = newpart.to_name unless NameLogic===newpart
|
104
|
+
if oldpart.simple?
|
105
|
+
simple? ? (self == oldpart ? newpart : self) :
|
106
|
+
parts.map{ |p| oldpart == p ? newpart : p }.to_name
|
107
|
+
elsif simple?
|
108
|
+
self
|
109
|
+
else
|
110
|
+
oldpart == parts[0, oldpart.size] ?
|
111
|
+
((self.size == oldpart.size) ? newpart :
|
112
|
+
(newpart.parts+(parts[oldpart.size,].lines.to_a)).to_name) : self
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def tag_name() simple? ? self : parts[-1] end
|
118
|
+
def left_name() simple? ? nil : self.class.new(parts[0..-2]) end
|
119
|
+
def trunk_name() simple? ? self : self.class.new(parts[0..-2]) end
|
120
|
+
def junction?() not simple? end
|
121
|
+
alias particle_names parts
|
122
|
+
|
123
|
+
def module_name() gsub(/^\*/,'X_').gsub(/[\b\s]+/,'_').camelcase end
|
124
|
+
def css_name() @css_name ||= key.gsub('*','X').gsub('+','-') end
|
125
|
+
|
126
|
+
def to_star() star? ? self : ?*+self end
|
127
|
+
def star?() simple? and self[0] == ?* end
|
128
|
+
def tag_star?() junction? and ?* == parts[-1][0] end
|
129
|
+
alias rstar? tag_star?
|
130
|
+
def star_rule(star)
|
131
|
+
star = star.to_s
|
132
|
+
[self, star.index(?*) ? star : ?*+star].to_name
|
133
|
+
end
|
134
|
+
|
135
|
+
alias blank? empty?
|
136
|
+
|
137
|
+
def pre_cgi() parts * '~plus~' end
|
138
|
+
def escape() gsub(' ','_') end
|
139
|
+
|
140
|
+
def to_url_key()
|
141
|
+
@url_key ||= decode_html.gsub(/[^\*#{WORD_RE}\s\+]/,' ').
|
142
|
+
strip.gsub(/[\s\_]+/,'_')
|
143
|
+
end
|
144
|
+
|
145
|
+
def piece_names()
|
146
|
+
simple? ? [self] : ([self] + trunk_name.piece_names + [tag_name]).uniq
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_show(context)
|
150
|
+
# FIXME this is not quite right. distinction is that is leaves blank parts blank.
|
151
|
+
(self =~/\b_(left|right|whole|self|user|main|\d+|L*R?)\b/) ?
|
152
|
+
to_absolute(context) : self
|
153
|
+
end
|
154
|
+
|
155
|
+
def escapeHTML(args)
|
156
|
+
args ? parts.map { |p| p =~ /^_/ and args[p] ? args[p] : p }*joint : self
|
157
|
+
end
|
158
|
+
|
159
|
+
def to_absolute_name(rel_name=nil)
|
160
|
+
(rel_name || self).to_name.to_absolute(self)
|
161
|
+
end
|
162
|
+
|
163
|
+
def nth_left(n)
|
164
|
+
(n >= size ? parts[0] : parts[0..-n-1]).to_name
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_absolute(context, params=nil)
|
168
|
+
context = context.to_name
|
169
|
+
parts.map do |part|
|
170
|
+
new_part = case part
|
171
|
+
#when /^_user$/i; user || part
|
172
|
+
when /^_main$/i; Wagn::Conf[:main_name]
|
173
|
+
when /^(_self|_whole|_)$/i; context
|
174
|
+
when /^_left$/i; context.trunk_name
|
175
|
+
when /^_right$/i; context.tag_name
|
176
|
+
when /^_(\d+)$/i;
|
177
|
+
pos = $~[1].to_i
|
178
|
+
pos = context.size if pos > context.size
|
179
|
+
context.parts[pos-1]
|
180
|
+
when /^_(L*)(R?)$/i
|
181
|
+
l_s, r_s = $~[1].size, $~[2].empty?
|
182
|
+
trunk = context.nth_left(l_s)
|
183
|
+
r= r_s ? trunk.to_s : trunk.tag_name
|
184
|
+
when /^_/
|
185
|
+
(params && ppart = params[part]) ? CGI.escapeHTML( ppart ) : part
|
186
|
+
else part
|
187
|
+
end.strip
|
188
|
+
new_part.empty? ? context : new_part
|
189
|
+
end * joint
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe NameLogic do
|
5
|
+
|
6
|
+
describe "#to_key" do
|
7
|
+
it "should remove spaces" do
|
8
|
+
"This Name".to_name.to_key.should == "this_name"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should singularize" do
|
12
|
+
"ethans".to_name.to_key.should == "ethan"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should underscore" do
|
16
|
+
"ThisThing".to_name.to_key.should == "this_thing"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should handle plus cards" do
|
20
|
+
"ThisThing+Ethans".to_name.to_key.should == "this_thing+ethan"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should retain * for star cards" do
|
24
|
+
"*right".to_name.to_key.should == "*right"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not singularize double s's" do
|
28
|
+
"grass".to_name.to_key.should == 'grass'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not singularize letter 'S'" do
|
32
|
+
'S'.to_name.to_key.should == 's'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should handle unicode characters" do
|
36
|
+
"Mañana".to_name.to_key.should == 'mañana'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should handle weird initial characters" do
|
40
|
+
'__you motha @#$'.to_name.to_key.should == 'you_motha'
|
41
|
+
'?!_you motha @#$'.to_name.to_key.should == 'you_motha'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should allow numbers" do
|
45
|
+
"3way".to_name.to_key.should == '3way'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "internal plurals" do
|
49
|
+
"cards hooks label foos".to_name.to_key.should == 'card_hook_label_foo'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should handle html entities" do
|
53
|
+
# This no longer takes off the s, is singularize broken now?
|
54
|
+
"Jean-françois Noubel".to_name.to_key.should == 'jean_françoi_noubel'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#to_absolute" do
|
59
|
+
it "handles _self, _whole, _" do
|
60
|
+
"_self".to_name.to_absolute("foo").should == "foo"
|
61
|
+
"_whole".to_name.to_absolute("foo").should == "foo"
|
62
|
+
"_".to_name.to_absolute("foo").should == "foo"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "handles _left" do
|
66
|
+
"_left+Z".to_name.to_absolute("A+B+C").should == "A+B+Z"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "handles white space" do
|
70
|
+
"_left + Z".to_name.to_absolute("A+B+C").should == "A+B+Z"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "handles _right" do
|
74
|
+
"_right+bang".to_name.to_absolute("nutter+butter").should == "butter+bang"
|
75
|
+
"C+_right".to_name.to_absolute("B+A").should == "C+A"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "handles leading +" do
|
79
|
+
"+bug".to_name.to_absolute("hum").should == "hum+bug"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "handles trailing +" do
|
83
|
+
"bug+".to_name.to_absolute("tracks").should == "bug+tracks"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "handles _(numbers)" do
|
87
|
+
"_1".to_name.to_absolute("A+B+C").should == "A"
|
88
|
+
"_1+_2".to_name.to_absolute("A+B+C").should == "A+B"
|
89
|
+
"_2+_3".to_name.to_absolute("A+B+C").should == "B+C"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "handles _LLR etc" do
|
93
|
+
"_R".to_name.to_absolute("A+B+C+D+E").should == "E"
|
94
|
+
"_L".to_name.to_absolute("A+B+C+D+E").should == "A+B+C+D"
|
95
|
+
"_LR".to_name.to_absolute("A+B+C+D+E").should == "D"
|
96
|
+
"_LL".to_name.to_absolute("A+B+C+D+E").should == "A+B+C"
|
97
|
+
"_LLR".to_name.to_absolute("A+B+C+D+E").should == "C"
|
98
|
+
"_LLL".to_name.to_absolute("A+B+C+D+E").should == "A+B"
|
99
|
+
"_LLLR".to_name.to_absolute("A+B+C+D+E").should == "B"
|
100
|
+
"_LLLL".to_name.to_absolute("A+B+C+D+E").should == "A"
|
101
|
+
end
|
102
|
+
|
103
|
+
context "mismatched requests" do
|
104
|
+
it "returns _self for _left or _right on non-junctions" do
|
105
|
+
"_left+Z".to_name.to_absolute("A").should == "A+Z"
|
106
|
+
"_right+Z".to_name.to_absolute("A").should == "A+Z"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "handles bogus numbers" do
|
110
|
+
"_1".to_name.to_absolute("A").should == "A"
|
111
|
+
"_1+_2".to_name.to_absolute("A").should == "A+A"
|
112
|
+
"_2+_3".to_name.to_absolute("A").should == "A+A"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "handles bogus _llr requests" do
|
116
|
+
"_R".to_name.to_absolute("A").should == "A"
|
117
|
+
"_L".to_name.to_absolute("A").should == "A"
|
118
|
+
"_LR".to_name.to_absolute("A").should == "A"
|
119
|
+
"_LL".to_name.to_absolute("A").should == "A"
|
120
|
+
"_LLR".to_name.to_absolute("A").should == "A"
|
121
|
+
"_LLL".to_name.to_absolute("A").should == "A"
|
122
|
+
"_LLLR".to_name.to_absolute("A").should == "A"
|
123
|
+
"_LLLL".to_name.to_absolute("A").should == "A"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
describe "#to_url_key" do
|
131
|
+
cardnames = ["GrassCommons.org", 'Oh you @##', "Alice's Restaurant!", "PB & J", "Mañana"].map(&:to_name)
|
132
|
+
|
133
|
+
cardnames.each do |cardname|
|
134
|
+
it "should have the same key as the name" do
|
135
|
+
k, k2 = cardname.to_key, cardname.to_url_key
|
136
|
+
#warn "cn tok #{cardname.inspect}, #{k.inspect}, #{k2.inspect}"
|
137
|
+
k.should == k2.to_name.to_key
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#valid" do
|
143
|
+
it "accepts valid names" do
|
144
|
+
"this+THAT".to_name.should be_valid
|
145
|
+
"THE*ONE*AND$!ONLY".to_name.should be_valid
|
146
|
+
end
|
147
|
+
|
148
|
+
it "rejects invalide names" do
|
149
|
+
"Tes~sd".to_name.should_not be_valid
|
150
|
+
"TEST/DDER".to_name.should_not be_valid
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#left_name" do
|
155
|
+
it "returns nil for non junction" do
|
156
|
+
"a".to_name.left_name.should == nil
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns parent for parent" do
|
160
|
+
"a+b+c+d".to_name.left_name.should == "a+b+c"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#tag_name" do
|
165
|
+
it "returns last part of plus card" do
|
166
|
+
"a+b+c".to_name.tag_name.should == "c"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "returns name of simple card" do
|
170
|
+
"a".to_name.tag_name.should == "a"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#css_name" do
|
175
|
+
it "subs pluses & stars" do
|
176
|
+
"Alpha?+*be-ta".to_name.css_name.should == "alpha-Xbe_tum"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "#replace_part" do
|
181
|
+
it "replaces first name part" do
|
182
|
+
'a+b'.to_name.replace_part('a','x').to_s.should == 'x+b'
|
183
|
+
end
|
184
|
+
it "replaces second name part" do
|
185
|
+
'a+b'.to_name.replace_part('b','x').to_s.should == 'a+x'
|
186
|
+
end
|
187
|
+
it "replaces two name parts" do
|
188
|
+
'a+b+c'.to_name.replace_part('a+b','x').to_s.should == 'x+c'
|
189
|
+
end
|
190
|
+
it "doesn't replace two part tag" do
|
191
|
+
'a+b+c'.to_name.replace_part('b+c','x').to_s.should == 'a+b+c'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/name_logic")
|
2
|
+
require 'active_support/inflector'
|
3
|
+
|
4
|
+
# Add new inflection rules using the following format
|
5
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
inflect.irregular 'grave', 'graveyard'
|
7
|
+
inflect.uncountable 'this'
|
8
|
+
# inflect.uncountable 'plus'
|
9
|
+
inflect.uncountable 'anonymous'
|
10
|
+
inflect.uncountable /^s$/
|
11
|
+
inflect.singular(/(ss)$/i, '\1')
|
12
|
+
inflect.plural(/(ss)$/i, '\1')
|
13
|
+
end
|
14
|
+
|
15
|
+
Object.send :include, NameLogic::ObjectMethods
|
data/test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class MyString < String
|
4
|
+
def initialize s
|
5
|
+
super s.to_s
|
6
|
+
@simple = s.index(?+)
|
7
|
+
@s= s.to_s
|
8
|
+
end
|
9
|
+
def to_s() self end
|
10
|
+
end
|
11
|
+
|
12
|
+
x='foobar'
|
13
|
+
|
14
|
+
puts "A string #{x}, and MyString: #{MyString.new(x)}, MyString.to_s: #{MyString.new(x).to_s}"
|
data/test2.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namelogic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gerry Gleason <gerryg@inbox.com>
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: htmlentities
|
16
|
+
requirement: &9304420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *9304420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: active_support
|
27
|
+
requirement: &9303140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *9303140
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &9318660 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *9318660
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rdoc
|
49
|
+
requirement: &9317780 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *9317780
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &9317080 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.1.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *9317080
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: &9314980 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *9314980
|
80
|
+
description: Wiki Segmented Name Logic
|
81
|
+
email: gerryg@inbox.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- Gemfile
|
88
|
+
- Gemfile.lock
|
89
|
+
- README.rdoc
|
90
|
+
- Rakefile
|
91
|
+
- VERSION
|
92
|
+
- lib/name_logic.rb
|
93
|
+
- spec/lib/name_logic_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- test.rb
|
96
|
+
- test2.rb
|
97
|
+
homepage: http://github.com/GerryG/namelogic/
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --main
|
103
|
+
- README.rdoc
|
104
|
+
- --inline-source
|
105
|
+
- --line-numbers
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: 4038131039544687550
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.15
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Wiki Segmented Name Logic
|
129
|
+
test_files: []
|