Class: BlocklyInterpreter::Block
- Inherits:
-
Object
- Object
- BlocklyInterpreter::Block
- Defined in:
- lib/blockly_interpreter/block.rb
Direct Known Subclasses
ConsoleInterpreter::ConsolePrintBlock, CoreBlocks::ArithmeticOperatorBlock, CoreBlocks::BooleanBlock, CoreBlocks::ComparisonOperatorBlock, CoreBlocks::ForBlock, CoreBlocks::ForEachBlock, CoreBlocks::GetVariableBlock, CoreBlocks::IfBlock, CoreBlocks::ListsCreateEmptyBlock, CoreBlocks::ListsCreateWithBlock, CoreBlocks::ListsGetIndexBlock, CoreBlocks::LogicNegateBlock, CoreBlocks::LogicalOperatorBlock, CoreBlocks::NumberBlock, CoreBlocks::ProcedureBlock, CoreBlocks::ProceduresIfReturnBlock, CoreBlocks::RepeatTimesBlock, CoreBlocks::SetVariableBlock, CoreBlocks::TextBlock, CoreBlocks::TextChangeCaseBlock, CoreBlocks::TextJoinBlock, ExtensionBlocks::DateTodayBlock, ExtensionBlocks::DebugMessageBlock, ExtensionBlocks::ListsAppendBlock, ExtensionBlocks::ListsConcatBlock, ExtensionBlocks::ListsIncludeOperatorBlock, ExtensionBlocks::ObjectPresentBlock, ExtensionBlocks::SwitchBlock, ExtensionBlocks::TextInflectBlock, OutputStringBlock, RaiseExceptionBlock
Class Attribute Summary collapse
-
.block_type ⇒ Object
Returns the value of attribute block_type.
Instance Attribute Summary collapse
-
#block_type ⇒ Object
readonly
Returns the value of attribute block_type.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#comment_pinned ⇒ Object
readonly
Returns the value of attribute comment_pinned.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#is_shadow ⇒ Object
(also: #is_shadow?)
readonly
Returns the value of attribute is_shadow.
-
#mutation ⇒ Object
readonly
Returns the value of attribute mutation.
-
#next_block ⇒ Object
readonly
Returns the value of attribute next_block.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #each_block(iterate_subblocks = true) {|_self| ... } ⇒ Object
- #execute_statement(execution_context) ⇒ Object
- #has_comment? ⇒ Boolean
- #has_position? ⇒ Boolean
-
#initialize(block_type, fields, values, statements, next_block, mutation, comment, comment_pinned, is_shadow, x, y) ⇒ Block
constructor
A new instance of Block.
- #to_dsl ⇒ Object
- #to_xml(options = {}) ⇒ Object
- #to_xml_element(document) ⇒ Object
- #value(execution_context) ⇒ Object
Constructor Details
#initialize(block_type, fields, values, statements, next_block, mutation, comment, comment_pinned, is_shadow, x, y) ⇒ Block
Returns a new instance of Block.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/blockly_interpreter/block.rb', line 11 def initialize(block_type, fields, values, statements, next_block, mutation, comment, comment_pinned, is_shadow, x, y) @block_type = block_type @fields = fields @values = values @statements = statements @next_block = next_block @mutation = mutation @comment = comment @comment_pinned = comment_pinned @is_shadow = is_shadow @x = x @y = y end |
Class Attribute Details
.block_type ⇒ Object
Returns the value of attribute block_type.
5 6 7 |
# File 'lib/blockly_interpreter/block.rb', line 5 def block_type @block_type end |
Instance Attribute Details
#block_type ⇒ Object (readonly)
Returns the value of attribute block_type.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def block_type @block_type end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def comment @comment end |
#comment_pinned ⇒ Object (readonly)
Returns the value of attribute comment_pinned.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def comment_pinned @comment_pinned end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def fields @fields end |
#is_shadow ⇒ Object (readonly) Also known as: is_shadow?
Returns the value of attribute is_shadow.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def is_shadow @is_shadow end |
#mutation ⇒ Object (readonly)
Returns the value of attribute mutation.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def mutation @mutation end |
#next_block ⇒ Object (readonly)
Returns the value of attribute next_block.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def next_block @next_block end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def statements @statements end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def values @values end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
8 9 10 |
# File 'lib/blockly_interpreter/block.rb', line 8 def y @y end |
Instance Method Details
#each_block(iterate_subblocks = true) {|_self| ... } ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/blockly_interpreter/block.rb', line 32 def each_block(iterate_subblocks = true) return to_enum(:each_block, iterate_subblocks) unless block_given? yield self if iterate_subblocks statements.each do |key, statement| statement.each_block(iterate_subblocks) do |block| yield block end end end if next_block next_block.each_block(iterate_subblocks) do |block| yield block end end end |
#execute_statement(execution_context) ⇒ Object
25 26 |
# File 'lib/blockly_interpreter/block.rb', line 25 def execute_statement(execution_context) end |
#has_comment? ⇒ Boolean
56 57 58 |
# File 'lib/blockly_interpreter/block.rb', line 56 def has_comment? comment.present? end |
#has_position? ⇒ Boolean
60 61 62 |
# File 'lib/blockly_interpreter/block.rb', line 60 def has_position? x || y end |
#to_dsl ⇒ Object
52 53 54 |
# File 'lib/blockly_interpreter/block.rb', line 52 def to_dsl BlocklyInterpreter::GenericBlockDSLGenerator.new(self).dsl end |
#to_xml(options = {}) ⇒ Object
108 109 110 111 112 |
# File 'lib/blockly_interpreter/block.rb', line 108 def to_xml( = {}) doc = Nokogiri::XML::Document.new element = to_xml_element(doc) element.to_xml( = {}) end |
#to_xml_element(document) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/blockly_interpreter/block.rb', line 64 def to_xml_element(document) tag_name = is_shadow ? 'shadow' : 'block' Nokogiri::XML::Element.new(tag_name, document).tap do |node| node['type'] = block_type node['x'] = x if x node['y'] = y if y node.add_child(mutation.dup) if mutation if comment comment_node = Nokogiri::XML::Element.new('comment', document) comment_node['pinned'] = 'true' if comment_pinned node.add_child comment_node end fields.each do |name, value| field_node = Nokogiri::XML::Element.new('field', document) field_node['name'] = name field_node.add_child Nokogiri::XML::Text.new(value, document) node.add_child field_node end values.each do |name, value| value_node = Nokogiri::XML::Element.new('value', document) value_node['name'] = name value_node.add_child value.to_xml_element(document) node.add_child value_node end statements.each do |name, value| statement_node = Nokogiri::XML::Element.new('statement', document) statement_node['name'] = name statement_node.add_child value.to_xml_element(document) node.add_child statement_node end if next_block next_block_node = Nokogiri::XML::Element.new('next_block', document) next_block_node.add_child next_block.to_xml_element(document) node.add_child next_block_node end end end |
#value(execution_context) ⇒ Object
28 29 30 |
# File 'lib/blockly_interpreter/block.rb', line 28 def value(execution_context) nil end |