Class: Q_Node
- Inherits:
-
Object
- Object
- Q_Node
- Defined in:
- lib/q-language/node.rb
Overview
Copyright © 2010-2011 Jesse Sielaff
Instance Attribute Summary collapse
-
#node_type ⇒ Object
readonly
Returns the value of attribute node_type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#block ⇒ Object
• User method Returns the block that contains the Node.
-
#initialize(node_type, name, klass, string, nodes) ⇒ Q_Node
constructor
A new instance of Q_Node.
-
#nodes ⇒ Object
• User method Returns an Array of the block Node’s contents.
-
#to_script ⇒ Object
• User method Returns a String representing the Node in Q script format.
Constructor Details
#initialize(node_type, name, klass, string, nodes) ⇒ Q_Node
Returns a new instance of Q_Node.
7 8 9 10 11 12 13 14 15 |
# File 'lib/q-language/node.rb', line 7 def initialize (node_type, name, klass, string, nodes) @node_type = node_type @value = case when name then name when klass then Object.const_get(:"Q#{klass}").from_s(string) when nodes then nodes.each {|node| node.instance_variable_set(:@block, self) } end end |
Instance Attribute Details
#node_type ⇒ Object (readonly)
Returns the value of attribute node_type.
17 18 19 |
# File 'lib/q-language/node.rb', line 17 def node_type @node_type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
17 18 19 |
# File 'lib/q-language/node.rb', line 17 def value @value end |
Instance Method Details
#block ⇒ Object
• User method Returns the block that contains the Node.
22 23 24 |
# File 'lib/q-language/node.rb', line 22 def block @block end |
#nodes ⇒ Object
• User method Returns an Array of the block Node’s contents. If the Node is not a block, returns nil.
30 31 32 |
# File 'lib/q-language/node.rb', line 30 def nodes @value if @node_type == :block end |
#to_script ⇒ Object
• User method Returns a String representing the Node in Q script format.
37 38 39 40 41 42 43 44 |
# File 'lib/q-language/node.rb', line 37 def to_script case @node_type when :block then "{#{@value.map {|n| n.to_script }.join ?\ }}" when :literal then "#{@value.to_qliteral}" when :method then "#@value" when :variable then ":#@value" end end |