Class: Template::Token

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, hidden = false) ⇒ Token

Returns a new instance of Token.



16
17
18
19
# File 'lib/template/token.rb', line 16

def initialize(value = nil, hidden = false)
  self.value = value unless value.nil?
  @hidden = hidden
end

Instance Attribute Details

#bool_stringsObject

Returns the value of attribute bool_strings.



13
14
15
# File 'lib/template/token.rb', line 13

def bool_strings
  @bool_strings
end

#commentObject

Returns the value of attribute comment.



14
15
16
# File 'lib/template/token.rb', line 14

def comment
  @comment
end

#default_valueObject

Returns the value of attribute default_value.



13
14
15
# File 'lib/template/token.rb', line 13

def default_value
  @default_value
end

#hiddenObject

Returns the value of attribute hidden.



13
14
15
# File 'lib/template/token.rb', line 13

def hidden
  @hidden
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/template/token.rb', line 13

def type
  @type
end

#validationObject

Returns the value of attribute validation.



14
15
16
# File 'lib/template/token.rb', line 14

def validation
  @validation
end

#validation_hintObject

Returns the value of attribute validation_hint.



14
15
16
# File 'lib/template/token.rb', line 14

def validation_hint
  @validation_hint
end

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/template/token.rb', line 13

def value
  @value
end

Instance Method Details

#to_sObject



78
79
80
81
82
83
84
85
# File 'lib/template/token.rb', line 78

def to_s
  case
  when self.type == :bool then
    bool_strings[value ? 1 : 0]
  else
    value
  end
end

#validate?(value) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
# File 'lib/template/token.rb', line 69

def validate?(value)
  case
  when self.type == :string then
    value.is_a?(String) && (validation.nil? || validation.match(value))
  when self.type == :bool then
    value.is_a?(TrueClass) or value.is_a?(FalseClass)
  end
end