Class: Template::Token
- Inherits:
-
Object
- Object
- Template::Token
- Defined in:
- lib/template/token.rb
Instance Attribute Summary collapse
-
#bool_strings ⇒ Object
Returns the value of attribute bool_strings.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#type ⇒ Object
Returns the value of attribute type.
-
#validation ⇒ Object
Returns the value of attribute validation.
-
#validation_hint ⇒ Object
Returns the value of attribute validation_hint.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value = nil, hidden = false) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ Object
- #validate?(value) ⇒ Boolean
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_strings ⇒ Object
Returns the value of attribute bool_strings.
13 14 15 |
# File 'lib/template/token.rb', line 13 def bool_strings @bool_strings end |
#comment ⇒ Object
Returns the value of attribute comment.
14 15 16 |
# File 'lib/template/token.rb', line 14 def comment @comment end |
#default_value ⇒ Object
Returns the value of attribute default_value.
13 14 15 |
# File 'lib/template/token.rb', line 13 def default_value @default_value end |
#hidden ⇒ Object
Returns the value of attribute hidden.
13 14 15 |
# File 'lib/template/token.rb', line 13 def hidden @hidden end |
#type ⇒ Object
Returns the value of attribute type.
13 14 15 |
# File 'lib/template/token.rb', line 13 def type @type end |
#validation ⇒ Object
Returns the value of attribute validation.
14 15 16 |
# File 'lib/template/token.rb', line 14 def validation @validation end |
#validation_hint ⇒ Object
Returns the value of attribute validation_hint.
14 15 16 |
# File 'lib/template/token.rb', line 14 def validation_hint @validation_hint end |
#value ⇒ Object
Returns the value of attribute value.
13 14 15 |
# File 'lib/template/token.rb', line 13 def value @value end |
Instance Method Details
#to_s ⇒ Object
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
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 |