Class: Bade::Node
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type, parent = nil) ⇒ Node
Returns a new instance of Node.
42
43
44
45
46
47
48
49
|
# File 'lib/bade/node.rb', line 42
def initialize(type, parent = nil)
@type = type
@childrens = []
if parent
parent << self
end
end
|
Instance Attribute Details
#childrens ⇒ Array<Node>
33
34
35
|
# File 'lib/bade/node.rb', line 33
def childrens
@childrens
end
|
24
25
26
|
# File 'lib/bade/node.rb', line 24
def data
@data
end
|
#escaped ⇒ TrueClass, FalseClass
37
38
39
|
# File 'lib/bade/node.rb', line 37
def escaped
@escaped
end
|
#lineno ⇒ Int
20
21
22
|
# File 'lib/bade/node.rb', line 20
def lineno
@lineno
end
|
#parent ⇒ Node
29
30
31
|
# File 'lib/bade/node.rb', line 29
def parent
@parent
end
|
#type ⇒ Symbol
15
16
17
|
# File 'lib/bade/node.rb', line 15
def type
@type
end
|
Class Method Details
.create(type, parent) ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/bade/node.rb', line 81
def self.create(type, parent)
klass = registered_types[type]
if klass.nil?
raise Parser::ParserInternalError, "undefined node type #{type.inspect}"
end
klass.new(type, parent)
end
|
.register_type(type, klass = self) ⇒ Object
72
73
74
75
76
|
# File 'lib/bade/node.rb', line 72
def self.register_type(type, klass = self)
raise StandardError, "Class #{klass} should be subclass of #{self}" unless klass <= Node
registered_types[type] = klass
end
|
.registered_types ⇒ Hash<Symbol, Class>
65
66
67
|
# File 'lib/bade/node.rb', line 65
def self.registered_types
@@registered_types ||= {}
end
|
Instance Method Details
53
54
55
56
57
58
|
# File 'lib/bade/node.rb', line 53
def << (node)
node.parent = self
@childrens << node
self
end
|