Class: Dentaku::Expression
- Inherits:
-
Object
- Object
- Dentaku::Expression
- Defined in:
- lib/dentaku/expression.rb
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #identifiers ⇒ Object
-
#initialize(string, variables = {}) ⇒ Expression
constructor
A new instance of Expression.
- #unbound? ⇒ Boolean
Constructor Details
#initialize(string, variables = {}) ⇒ Expression
Returns a new instance of Expression.
7 8 9 10 11 12 13 |
# File 'lib/dentaku/expression.rb', line 7 def initialize(string, variables={}) @raw = string @tokenizer ||= Tokenizer.new @tokens = @tokenizer.tokenize(@raw) @variables = Hash[variables.map { |k,v| [k.to_s, v] }] replace_identifiers_with_values end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
5 6 7 |
# File 'lib/dentaku/expression.rb', line 5 def tokens @tokens end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
5 6 7 |
# File 'lib/dentaku/expression.rb', line 5 def variables @variables end |
Instance Method Details
#identifiers ⇒ Object
15 16 17 |
# File 'lib/dentaku/expression.rb', line 15 def identifiers @tokens.select { |t| t.category == :identifier }.map { |t| t.value } end |
#unbound? ⇒ Boolean
19 20 21 |
# File 'lib/dentaku/expression.rb', line 19 def unbound? identifiers.any? end |