Class: BlocklyInterpreter::Program
- Inherits:
-
Object
- Object
- BlocklyInterpreter::Program
show all
- Includes:
- DSLGenerator
- Defined in:
- lib/blockly_interpreter/program.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#deep_flatten, #formatted_keyword_args, #indent, #keyword_args_without_defaults, #method_call, #method_call_with_block_or_nothing, #method_call_with_possible_block, #start_block_to_dsl, #strip_trailing_whitespace, #timestamp_to_dsl
Constructor Details
#initialize(first_block, procedures = {}) ⇒ Program
7
8
9
10
|
# File 'lib/blockly_interpreter/program.rb', line 7
def initialize(first_block, procedures = {})
@first_block = first_block
@procedures = procedures
end
|
Instance Attribute Details
#first_block ⇒ Object
Returns the value of attribute first_block.
5
6
7
|
# File 'lib/blockly_interpreter/program.rb', line 5
def first_block
@first_block
end
|
#procedures ⇒ Object
Returns the value of attribute procedures.
5
6
7
|
# File 'lib/blockly_interpreter/program.rb', line 5
def procedures
@procedures
end
|
Instance Method Details
#each_block(iterate_subblocks = true) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/blockly_interpreter/program.rb', line 12
def each_block(iterate_subblocks = true)
return to_enum(:each_block, iterate_subblocks) unless block_given?
if first_block
first_block.each_block(iterate_subblocks) do |block|
yield block
end
end
procedures.values.each do |procedure|
procedure.each_block(iterate_subblocks) do |block|
yield block
end
end
end
|
#to_dsl ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/blockly_interpreter/program.rb', line 28
def to_dsl
dsl = ""
procedure_dsls = procedures.map do |key, start_block|
start_block_to_dsl(start_block)
end
procedures_dsl = method_call_with_block_or_nothing("procedures", "", procedure_dsls.join("\n"))
[procedures_dsl, start_block_to_dsl(first_block)].compact.join("\n")
end
|
#to_xml(options = {}) ⇒ Object
48
49
50
|
# File 'lib/blockly_interpreter/program.rb', line 48
def to_xml(options = {})
to_xml_document.to_xml(options)
end
|
#to_xml_document ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/blockly_interpreter/program.rb', line 39
def to_xml_document
Nokogiri::XML::Document.new.tap do |doc|
doc.add_child first_block.to_xml_element(doc)
procedures.each do |_, procedure|
doc.add_child procedure.to_xml_element(doc)
end
end
end
|