Class: Token::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/token/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Token

Returns a new instance of Token.



6
7
8
9
10
11
12
# File 'lib/token/token.rb', line 6

def initialize(args = {})

  @name = args[:name]
  @types = args[:types]
  @children = args[:children]      
  @content = args[:content] || ""
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/token/token.rb', line 4

def children
  @children
end

#contentObject (readonly)

Returns the value of attribute content.



4
5
6
# File 'lib/token/token.rb', line 4

def content
  @content
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/token/token.rb', line 4

def name
  @name
end

#typesObject (readonly)

Returns the value of attribute types.



4
5
6
# File 'lib/token/token.rb', line 4

def types
  @types
end

Class Method Details

.process_options(options = {}) ⇒ Object

Note:

should only be performed once!!!



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/token/token.rb', line 15

def self.process_options(options = {})

  # pushing defaults
  options[:template] ||= :default
  
  options[:html]     = { 
    :class => options[:token].to_s
  }.merge(options[:html] || {})
  
  options[:area]     ||= :body      

  %w(handler token template html area).each do |opt|        
    self.class_variable_set("@@#{opt}".to_sym, options[opt.to_sym])      
    
    class_eval "
      def self.#{opt}
        return self.class_variable_get(:@@#{opt}) if self.class_variable_defined? :@@#{opt}
      end
      
      def #{opt}
        self.class.#{opt}
      end
    "
  end
end

Instance Method Details

#to_sObject



41
42
43
# File 'lib/token/token.rb', line 41

def to_s
  self.class.class_variable_get(:@@token).to_s.capitalize
end