Class: Transmogrifier::ArrayNode
- Inherits:
-
Node
- Object
- Node
- Transmogrifier::ArrayNode
show all
- Extended by:
- Forwardable
- Defined in:
- lib/transmogrifier/nodes/array_node.rb
Instance Method Summary
collapse
Methods inherited from Node
#append, for, #modify, #raw
Constructor Details
#initialize(array) ⇒ ArrayNode
Returns a new instance of ArrayNode.
7
8
9
|
# File 'lib/transmogrifier/nodes/array_node.rb', line 7
def initialize(array)
@array = array
end
|
Instance Method Details
#clone(key) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/transmogrifier/nodes/array_node.rb', line 21
def clone(key)
matching_nodes = find_nodes(key)
raise "Multiple nodes match #{key}, clone criteria ambiguous" if matching_nodes.length > 1
Marshal.load(Marshal.dump(matching_nodes.first))
end
|
#delete(key) ⇒ Object
28
29
30
31
32
|
# File 'lib/transmogrifier/nodes/array_node.rb', line 28
def delete(key)
matching_nodes = find_nodes(key)
deleted_nodes = matching_nodes.each { |n| @array.delete(n) }
deleted_nodes.length > 1 ? deleted_nodes : deleted_nodes.first
end
|
#find_all(keys) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/transmogrifier/nodes/array_node.rb', line 11
def find_all(keys)
first_key, *remaining_keys = keys
if first_key.nil?
[self]
else
find_nodes(first_key).flat_map { |x| Node.for(x).find_all(remaining_keys) }
end
end
|