Class: Proforma::HashEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/proforma/hash_evaluator.rb

Overview

This class will serve as the evaluator that gets shipped with the base framework. Other packages can extend or create their own and plug them into the rendering pipeline. This, being a prototype for customizable evaluators, just provides basic evaluation:

  • it can only handle hashes for value extraction

  • if text is prefixed with a dollar sign and colon then it means it will be dynamically evaluated against the record. For example: $id

Constant Summary collapse

PROPERTY_PREFIX =
'$'

Instance Method Summary collapse

Instance Method Details

#text(object, expression) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/proforma/hash_evaluator.rb', line 28

def text(object, expression)
  if expression.to_s.start_with?(PROPERTY_PREFIX)
    value(object, expression.to_s[PROPERTY_PREFIX.length..-1])
  else
    expression
  end
end

#value(object, expression) ⇒ Object



21
22
23
24
25
26
# File 'lib/proforma/hash_evaluator.rb', line 21

def value(object, expression)
  return object if expression.to_s.empty?
  return nil    unless object.is_a?(Hash)

  object[expression.to_s] || object[expression.to_s.to_sym]
end