Class: Twig::Token
- Inherits:
-
Object
- Object
- Twig::Token
- Defined in:
- lib/twig/token.rb
Constant Summary collapse
- EOF_TYPE =
:eof- TEXT_TYPE =
:text- BLOCK_START_TYPE =
:block_start- VAR_START_TYPE =
:var_start- BLOCK_END_TYPE =
:block_end- VAR_END_TYPE =
:var_end- NAME_TYPE =
:name- SYMBOL_TYPE =
:symbol- CLASS_VAR_TYPE =
:class_var- NUMBER_TYPE =
:number- STRING_TYPE =
:string- OPERATOR_TYPE =
:operator- PUNCTUATION_TYPE =
:punctuation- INTERPOLATION_START_TYPE =
:interpolation_start- INTERPOLATION_END_TYPE =
:interpolation_end- TOKEN_TO_ENGLISH =
{ EOF_TYPE => 'end of template', TEXT_TYPE => 'text', BLOCK_START_TYPE => 'begin of statement block', VAR_START_TYPE => 'begin of print statement', BLOCK_END_TYPE => 'end of statement block', VAR_END_TYPE => 'end of print statement', NAME_TYPE => 'name', NUMBER_TYPE => 'number', STRING_TYPE => 'string', OPERATOR_TYPE => 'operator', PUNCTUATION_TYPE => 'punctuation', INTERPOLATION_START_TYPE => 'begin of string interpolation', INTERPOLATION_END_TYPE => 'end of string interpolation', SYMBOL_TYPE => 'symbol', }.freeze
Instance Attribute Summary collapse
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
-
#initialize(type, value, lineno) ⇒ Token
constructor
A new instance of Token.
- #test(type, values = nil) ⇒ Object
- #to_english ⇒ Object
Constructor Details
#initialize(type, value, lineno) ⇒ Token
40 41 42 43 44 |
# File 'lib/twig/token.rb', line 40 def initialize(type, value, lineno) @type = type @value = value @lineno = lineno end |
Instance Attribute Details
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
38 39 40 |
# File 'lib/twig/token.rb', line 38 def lineno @lineno end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
38 39 40 |
# File 'lib/twig/token.rb', line 38 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
38 39 40 |
# File 'lib/twig/token.rb', line 38 def value @value end |
Class Method Details
.type_to_english(type) ⇒ Object
68 69 70 71 72 |
# File 'lib/twig/token.rb', line 68 def self.type_to_english(type) TOKEN_TO_ENGLISH.fetch(type) do raise ArgumentError, "Token of type \"#{type}\" does not exist." end end |
Instance Method Details
#debug ⇒ Object
60 61 62 |
# File 'lib/twig/token.rb', line 60 def debug [type, value] end |
#test(type, values = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/twig/token.rb', line 47 def test(type, values = nil) if values.nil? && !type.is_a?(Symbol) values = type type = NAME_TYPE end @type == type && ( values.nil? || (values.is_a?(Array) && values.include?(@value)) || (@value == values) ) end |
#to_english ⇒ Object
64 65 66 |
# File 'lib/twig/token.rb', line 64 def to_english self.class.type_to_english(@type) end |