Class: Changit::Lexer
- Inherits:
-
Object
- Object
- Changit::Lexer
- Defined in:
- lib/changit/lexer.rb,
lib/changit/lexer/section_token.rb,
lib/changit/lexer/key_value_token.rb
Defined Under Namespace
Classes: KeyValueToken, SectionToken
Constant Summary collapse
- RULES =
[ [/\[(.*?)\]/, SectionToken].freeze, [/^[^(=|\[|\s)]*\s*\=\s*[^(=|\[|\])]*/, KeyValueToken].freeze ].freeze
Instance Attribute Summary collapse
-
#original_expression ⇒ Object
readonly
Returns the value of attribute original_expression.
-
#token_hash ⇒ Object
readonly
Returns the value of attribute token_hash.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(expression) ⇒ Lexer
constructor
A new instance of Lexer.
- #reconstruct_tokens_from_hash! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(expression) ⇒ Lexer
10 11 12 13 14 |
# File 'lib/changit/lexer.rb', line 10 def initialize(expression) @original_expression = expression @tokens = tokenize @token_hash = to_hash end |
Instance Attribute Details
#original_expression ⇒ Object (readonly)
Returns the value of attribute original_expression.
8 9 10 |
# File 'lib/changit/lexer.rb', line 8 def original_expression @original_expression end |
#token_hash ⇒ Object (readonly)
Returns the value of attribute token_hash.
8 9 10 |
# File 'lib/changit/lexer.rb', line 8 def token_hash @token_hash end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
8 9 10 |
# File 'lib/changit/lexer.rb', line 8 def tokens @tokens end |
Instance Method Details
#reconstruct_tokens_from_hash! ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/changit/lexer.rb', line 20 def reconstruct_tokens_from_hash! tokens = [] @token_hash.each do |section, key_value| tokens << SectionToken.new(section) key_value.each { |lhs, rhs| tokens << KeyValueToken.new("#{lhs} = #{rhs}") } end @tokens = tokens end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/changit/lexer.rb', line 16 def to_s @tokens.map(&:to_s).join end |