Class: Code::Node::Dictionary::KeyValue
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Dictionary::KeyValue
- Defined in:
- lib/code/node/dictionary.rb
Instance Attribute Summary collapse
-
#resolve_key ⇒ Object
readonly
Returns the value of attribute resolve_key.
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ KeyValue
constructor
A new instance of KeyValue.
- #resolve_key? ⇒ Boolean
Methods inherited from Code::Node
Constructor Details
#initialize(parsed) ⇒ KeyValue
Returns a new instance of KeyValue.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/code/node/dictionary.rb', line 9 def initialize(parsed) return if parsed.blank? if (name_code = parsed.delete(:name_code)) if name_code.key?(:code) @key = Node::String.new([{ text: name_code.delete(:name).presence }]) @value = Node::Code.new(name_code.delete(:code).presence) @resolve_key = false else @key = Node::Call.new({ name: name_code.delete(:name).presence }) @value = @key @resolve_key = true end elsif (statement_code = parsed.delete(:statement_code)) @key = Node::Statement.new(statement_code.delete(:statement).presence) if statement_code.key?(:code) @value = Node::Code.new(statement_code.delete(:code).presence) @resolve_key = false else @value = @key @resolve_key = true end else @key = @value = Node::Code.new(parsed.delete(:code).presence) @resolve_key = true end end |
Instance Attribute Details
#resolve_key ⇒ Object (readonly)
Returns the value of attribute resolve_key.
7 8 9 |
# File 'lib/code/node/dictionary.rb', line 7 def resolve_key @resolve_key end |
Instance Method Details
#evaluate(**args) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/code/node/dictionary.rb', line 40 def evaluate(**args) key = resolve_key? ? @key&.resolve(**args) : @key&.evaluate(**args) key ||= Object::Nothing.new value = @value.evaluate(**args) [key, value] end |
#resolve_key? ⇒ Boolean
47 48 49 |
# File 'lib/code/node/dictionary.rb', line 47 def resolve_key? !!resolve_key end |