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.



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

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

Instance Attribute Details

#bool_stringsObject

Returns the value of attribute bool_strings.



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

def bool_strings
  @bool_strings
end

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

#default_valueObject

Returns the value of attribute default_value.



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

def default_value
  @default_value
end

#hiddenObject

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#validationObject

Returns the value of attribute validation.



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

def validation
  @validation
end

#validation_hintObject

Returns the value of attribute validation_hint.



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

def validation_hint
  @validation_hint
end

#valueObject

Returns the value of attribute value.



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

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