lib/proforma/hash_evaluator.rb in proforma-1.0.0.pre.alpha vs lib/proforma/hash_evaluator.rb in proforma-1.0.0

- old
+ new

@@ -12,27 +12,23 @@ # 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 + # evaluated against the record. For example: $id class HashEvaluator - PROPERTY_PREFIX = '$:' + PROPERTY_PREFIX = '$' def value(object, expression) return object if expression.to_s.empty? return nil unless object.is_a?(Hash) - if object.key?(expression.to_s) - object[expression.to_s] - elsif object.key?(expression.to_s.to_sym) - object[expression.to_s.to_sym] - end + object[expression.to_s] || object[expression.to_s.to_sym] end def text(object, expression) if expression.to_s.start_with?(PROPERTY_PREFIX) - value(object, expression.to_s[2..-1]) + value(object, expression.to_s[PROPERTY_PREFIX.length..-1]) else expression end end end