Class: Liquidice::Transformer::Nodes::Base
- Inherits:
-
Object
- Object
- Liquidice::Transformer::Nodes::Base
show all
- Defined in:
- lib/liquidice/transformer/nodes/base.rb
Constant Summary
collapse
- @@dot_id_counter =
0
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(original_text:, children: [], options: {}) ⇒ Base
Returns a new instance of Base.
7
8
9
10
11
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 7
def initialize(original_text:, children: [], options: {})
@original_text, @children, @options = original_text, children, options
validate!
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5
6
7
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 5
def children
@children
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 5
def options
@options
end
|
#original_text ⇒ Object
Returns the value of attribute original_text.
5
6
7
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 5
def original_text
@original_text
end
|
Instance Method Details
#can_be_merged?(other) ⇒ Boolean
29
30
31
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 29
def can_be_merged?(other)
false
end
|
#dot_id ⇒ Object
35
36
37
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 35
def dot_id
@dot_id ||= @@dot_id_counter += 1
end
|
#strict_mode? ⇒ Boolean
17
18
19
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 17
def strict_mode?
false
end
|
#to_s ⇒ Object
13
14
15
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 13
def to_s
raise NotImplementedError
end
|
21
22
23
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 21
def transform!
end
|
#validate! ⇒ Object
25
26
27
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 25
def validate!
end
|
#write_dot(io) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 39
def write_dot(io)
io.puts "node#{dot_id} [label=\"'#{original_text}'\"];"
children.each do |child|
io.puts "node#{dot_id} -> node#{child.dot_id};"
child.write_dot(io)
end
end
|
#write_dot_file(fname) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/liquidice/transformer/nodes/base.rb', line 47
def write_dot_file(fname)
File.open(fname + ".dot","w") do |file|
file.puts "digraph G {"
write_dot(file)
file.puts "}"
end
end
|