Class: Dentaku::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/dentaku/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tokensObject (readonly)

Returns the value of attribute tokens.



5
6
7
# File 'lib/dentaku/expression.rb', line 5

def tokens
  @tokens
end

#variablesObject (readonly)

Returns the value of attribute variables.



5
6
7
# File 'lib/dentaku/expression.rb', line 5

def variables
  @variables
end

Instance Method Details

#identifiersObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/dentaku/expression.rb', line 19

def unbound?
  identifiers.any?
end