Class: JsonToToon::ContainerNode

Inherits:
DataNode
  • Object
show all
Defined in:
lib/json_to_toon/container_node.rb

Direct Known Subclasses

ArrayNode, ObjectNode

Instance Attribute Summary collapse

Attributes inherited from DataNode

#indentation_level, #parent

Instance Method Summary collapse

Methods inherited from DataNode

#indent, #root

Constructor Details

#initialize(parent = nil) ⇒ ContainerNode

Returns a new instance of ContainerNode.



9
10
11
12
# File 'lib/json_to_toon/container_node.rb', line 9

def initialize(parent = nil)
  super
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/json_to_toon/container_node.rb', line 7

def children
  @children
end

Instance Method Details

#add_child(child) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/json_to_toon/container_node.rb', line 14

def add_child(child)
  raise ArgumentError, 'Can only add objects of type DataNode as children.' unless child.is_a?(DataNode)

  @children << child
end

#to_sObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/json_to_toon/container_node.rb', line 20

def to_s
  raise NotImplementedError, "#{self.class} must implement the 'to_s' method for specific formatting."
end