lib/pione/util/evaluatable.rb in pione-0.3.2 vs lib/pione/util/evaluatable.rb in pione-0.4.0
- old
+ new
@@ -4,47 +4,33 @@
# expression string.
module Evaluatable
# Evaluate the string as a PIONE expression and get the result value as model object.
#
# @param str [String]
- # a PIONE expression string
- # @param domain_info [DomainInfo]
- # domain info
- # @return [BasicModel]
- # the result of evaluation
- def val!(str, domain_info=nil)
- domain_info = load_domain_info unless domain_info
- env = domain_info.env
+ # a PIONE expression
+ # @param domain_dump [DomainDump]
+ # a domain dump object
+ # @return [Object]
+ # the evaluation value
+ 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
# Evaluate the string as a PIONE expression and get the result value as a textized string.
#
# @param str [String]
- # a PIONE expression string
- # @param domain_info [DomainInfo]
- # domain info
+ # a PIONE expression
+ # @param domain_dump [DomainDump]
+ # a domain dump object
# @return [String]
# the result of evaluation as an embeddable string
- def val(str, domain_info=nil)
- domain_info = load_domain_info unless domain_info
- env = domain_info.env
- val!(str, domain_info).call_pione_method(env, "textize", []).first.value
- end
-
- private
-
- # Load default domain info file.
- def load_domain_info
- location = Location["./.domain.dump"]
- if location.exist?
- System::DomainInfo.read(location)
- else
- System::DomainInfo.new(Lang::Environment.new)
- end
+ 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
end
end
end