lib/code/node/dictionnary.rb in code-ruby-0.4.0 vs lib/code/node/dictionnary.rb in code-ruby-0.5.0

- old
+ new

@@ -1,21 +1,32 @@ class Code class Node class Dictionnary < Node - def initialize(key_values) - if key_values.blank? - @key_values = [] - else - @key_values = - key_values.map do |key_value| - ::Code::Node::DictionnaryKeyValue.new(key_value) - end + class KeyValue < Node + def initialize(parsed) + if parsed.key?(:statement) + @key = Node::Statement.new(parsed.delete(:statement)) + elsif parsed.key?(:name) + @key = Node::String.new([{ text: parsed.delete(:name) }]) + end + + @value = Node::Code.new(parsed.delete(:value)) end + + def evaluate(**args) + [@key.evaluate(**args), @value.evaluate(**args)] + end end + def initialize(parsed) + parsed = [] if parsed == "" + @key_values = + parsed.map { |key_value| Node::Dictionnary::KeyValue.new(key_value) } + end + def evaluate(**args) ::Code::Object::Dictionnary.new( - @key_values.map { |key_value| key_value.evaluate(**args) }.to_h, + @key_values.map { |key_value| key_value.evaluate(**args) }.to_h ) end end end end