class SmartName

Constants

JOINT_RE
OK4KEY_RE
RUBYENCODING

Attributes

key[R]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~

s[R]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~

to_s[R]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~

Public Class Methods

banned_re() click to toggle source
   # File lib/smart_name.rb
56 def banned_re
57   %r{#{ (['['] + banned_array << joint) * '\\' + ']' }}
58 end
known_name(str) click to toggle source
   # File lib/smart_name.rb
44 def known_name str
45   @@name2nameobject[str]
46 end
new(obj) click to toggle source
Calls superclass method
   # File lib/smart_name.rb
38 def new obj
39   return obj if obj.is_a? self.class
40   str = stringify obj
41   known_name(str) || super(str.strip)
42 end
new(str) click to toggle source
   # File lib/smart_name.rb
80 def initialize str
81   @s = str.to_s.strip
82   @s = @s.encode('UTF-8') if RUBYENCODING
83   initialize_parts
84   @key = @part_keys.join(self.class.joint)
85   @@name2nameobject[str] = self
86 end
stable_uninflect(name) click to toggle source

Sometimes the core rule “the key's key must be itself” (called “stable” below) is violated eg. it fails with singularize as uninflect method for Matthias -> Matthia -> Matthium Usually that means the name is a proper noun and not a plural. You can choose between two solutions:

  1. don't uninflect if the uninflected key is not stable (stabilize = false) (probably the best choice because you want Matthias not to be the same as Matthium)

  2. uninflect until the key is stable (stabilize = true)

   # File lib/smart_name.rb
67 def stable_uninflect name
68   key_one = name.send(SmartName.uninflect)
69   key_two = key_one.send(SmartName.uninflect)
70   return key_one unless key_one != key_two
71   SmartName.stabilize ? stable_uninflect(key_two) : name
72 end
stringify(obj) click to toggle source
   # File lib/smart_name.rb
48 def stringify obj
49   if obj.is_a?(Array)
50     obj.map(&:to_s) * joint
51   else
52     obj.to_s
53   end
54 end
substitute!(str, hash) click to toggle source

HACK. This doesn't belong here. shouldn't it use inclusions???

   # File lib/smart_name/manipulate.rb
65 def self.substitute! str, hash
66   hash.keys.each do |var|
67     str.gsub! var_re do |x|
68       hash[var.to_sym]
69     end
70   end
71   str
72 end

Public Instance Methods

==(other) click to toggle source
    # File lib/smart_name.rb
104 def == other
105   other_key =
106     case
107     when other.respond_to?(:key)     then other.key
108     when other.respond_to?(:to_name) then other.to_name.key
109     else                                  other.to_s
110     end
111   other_key == key
112 end
inspect() click to toggle source
    # File lib/smart_name.rb
100 def inspect
101   "<#{self.class.name} key=#{key}[#{self}]>"
102 end
length() click to toggle source
   # File lib/smart_name.rb
92 def length
93   parts.length
94 end
size() click to toggle source
   # File lib/smart_name.rb
96 def size
97   to_s.size
98 end
to_name() click to toggle source
   # File lib/smart_name.rb
88 def to_name
89   self
90 end