Module: Pione::Util::Evaluatable

Included in:
Pione
Defined in:
lib/pione/util/evaluatable.rb

Overview

Evaluatable is a module for providing to ability to evaluate PIONE expression string.

Instance Method Summary collapse

Instance Method Details

#val(str, domain_dump = nil) ⇒ String

Evaluate the string as a PIONE expression and get the result value as a textized string.

Parameters:

  • str (String)

    a PIONE expression

  • domain_dump (DomainDump) (defaults to: nil)

    a domain dump object

Returns:

  • (String)

    the result of evaluation as an embeddable string



30
31
32
33
# File 'lib/pione/util/evaluatable.rb', line 30

def val(str, domain_dump=nil)
  env = domain_dump ? domain_dump.env : Lang::Environment.new
  val!(str, domain_dump).call_pione_method(env, "textize", []).first.value
end

#val!(str, domain_dump = nil) ⇒ Object

Evaluate the string as a PIONE expression and get the result value as model object.

Parameters:

  • str (String)

    a PIONE expression

  • domain_dump (DomainDump) (defaults to: nil)

    a domain dump object

Returns:

  • (Object)

    the evaluation value



14
15
16
17
18
19
20
# File 'lib/pione/util/evaluatable.rb', line 14

def val!(str, domain_dump=nil)
  env = domain_dump ? domain_dump.env : Lang::Environment.new
  option = {package_name: env.current_package_id, filename: "pione-eval"}
  Lang::DocumentTransformer.new.apply(
    Lang::DocumentParser.new.expr.parse(str), option
  ).eval(env)
end