Class: Card::Name::ViewName

Inherits:
SmartName
  • Object
show all
Defined in:
lib/card/name/view_name.rb

Constant Summary collapse

@@name2viewnameobject =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ViewName

Returns a new instance of ViewName.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/card/name/view_name.rb', line 23

def initialize str
  @s = str.to_s.strip
  @s = @s.encode("UTF-8") if RUBYENCODING
  @key = if @s.index(self.class.joint)
           @parts = @s.split(/\s*#{JOINT_RE}\s*/)
      @parts << "" if @s[-1, 1] == self.class.joint
      @simple = false
      @parts.map { |p| p.to_name.key } * self.class.joint
         else
           @parts = [str]
      @simple = true
      str.empty? ? "" : simple_key
    end
  @@name2viewnameobject[str] = self
end

Class Method Details

.new(obj) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/card/name/view_name.rb', line 12

def new obj
  return obj if self.class === obj
  str = Array === obj ? obj * joint : obj.to_s
  if known_name = @@name2viewnameobject[str]
    known_name
  else
    super str.strip
  end
end

Instance Method Details

#simple_keyObject



39
40
41
# File 'lib/card/name/view_name.rb', line 39

def simple_key
  decoded.underscore.gsub(/[^#{OK4KEY_RE}]+/, "_").split(/_+/).reject(&:empty?) * "_"
end

#to_viewnameObject



43
44
45
# File 'lib/card/name/view_name.rb', line 43

def to_viewname
  self
end