Class: Expressionist::Expression

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

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Expression

Returns a new instance of Expression.



10
11
12
13
14
15
16
# File 'lib/expressionist/expression.rb', line 10

def initialize(value)
  if value.kind_of?(Parser)
    @parser = value
  else
    @executable = value
  end
end

Instance Method Details

#call(context = {}, executable = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/expressionist/expression.rb', line 22

def call(context = {}, executable = nil)
  executable ||= self.executable

  args = executable[1..-1].map do |exp|
    if exp.kind_of?(Array)
      call(context, exp)
    else
      exp
    end
  end

  function = Functions.get(executable[0])
  unless function
    raise ArgumentError, "Function #{executable[0].inspect} is missing"
  end

  function.call(context, *args)
end

#executableObject



18
19
20
# File 'lib/expressionist/expression.rb', line 18

def executable
  @executable ||= @parser.executable
end