Class: SpotFeel::QualifiedName

Inherits:
Node
  • Object
show all
Defined in:
lib/spot_feel/nodes.rb

Overview

  1. qualified name = name , { “.” , name } ;

Instance Method Summary collapse

Methods inherited from Node

#qualified_names_in_context, #raise_evaluation_error

Instance Method Details

#eval(context = {}) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/spot_feel/nodes.rb', line 226

def eval(context = {})
  if tail.empty?
    raise_evaluation_error(head.text_value, context) if SpotFeel.config.strict && !context.key?(head.text_value.to_sym)
    context[head.text_value.to_sym]
  else
    tail.elements.flat_map { |element| element.name.text_value.split('.') }.inject(context[head.text_value.to_sym]) do |hash, key|
      raise_evaluation_error("#{head.text_value}#{tail.text_value}", context) if SpotFeel.config.strict && (hash.blank? || !hash.key?(key.to_sym))
      return nil unless hash
      hash[key.to_sym]
    end
  end
end