Class: Card::ViewName

Inherits:
SmartName
  • Object
show all
Defined in:
lib/card/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.



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

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



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

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



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

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

#to_viewnameObject



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

def to_viewname
  self
end