Class: Parselly::Node::ChildList

Inherits:
Array
  • Object
show all
Defined in:
lib/parselly/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ ChildList

Returns a new instance of ChildList.



33
34
35
36
# File 'lib/parselly/node.rb', line 33

def initialize(owner)
  @owner = owner
  super()
end

Instance Method Details

#<<(node) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/parselly/node.rb', line 38

def <<(node)
  return self if node.nil?

  @owner.__send__(:adopt_child, node)
  super(node)
  @owner.__send__(:invalidate_cache)
  self
end

#[]=(index, node) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/parselly/node.rb', line 57

def []=(index, node)
  old_node = self[index]
  @owner.__send__(:detach_child, old_node) if old_node
  @owner.__send__(:adopt_child, node)
  super
  @owner.__send__(:invalidate_cache)
  node
end

#clearObject



87
88
89
90
91
92
# File 'lib/parselly/node.rb', line 87

def clear
  each { |node| @owner.__send__(:detach_child, node) }
  result = super
  @owner.__send__(:invalidate_cache)
  result
end

#concat(nodes) ⇒ Object



52
53
54
55
# File 'lib/parselly/node.rb', line 52

def concat(nodes)
  nodes.each { |node| self << node }
  self
end

#delete(node) ⇒ Object



80
81
82
83
84
85
# File 'lib/parselly/node.rb', line 80

def delete(node)
  deleted = super
  @owner.__send__(:detach_child, deleted) if deleted
  @owner.__send__(:invalidate_cache) if deleted
  deleted
end

#delete_at(index) ⇒ Object



73
74
75
76
77
78
# File 'lib/parselly/node.rb', line 73

def delete_at(index)
  node = super
  @owner.__send__(:detach_child, node) if node
  @owner.__send__(:invalidate_cache)
  node
end

#insert(index, *nodes) ⇒ Object



66
67
68
69
70
71
# File 'lib/parselly/node.rb', line 66

def insert(index, *nodes)
  nodes.each { |node| @owner.__send__(:adopt_child, node) }
  result = super
  @owner.__send__(:invalidate_cache)
  result
end

#push(*nodes) ⇒ Object



47
48
49
50
# File 'lib/parselly/node.rb', line 47

def push(*nodes)
  nodes.each { |node| self << node }
  self
end