Class: Easydsl::Node
- Inherits:
-
Object
- Object
- Easydsl::Node
- Defined in:
- lib/easydsl/node.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#singleton ⇒ Object
readonly
Returns the value of attribute singleton.
Instance Method Summary collapse
- #all_nodes ⇒ Object
- #define(&block) ⇒ Object
-
#initialize(name, args, index, parent, node_builders = []) ⇒ Node
constructor
A new instance of Node.
- #max_index ⇒ Object
- #nodes ⇒ Object
Constructor Details
#initialize(name, args, index, parent, node_builders = []) ⇒ Node
Returns a new instance of Node.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/easydsl/node.rb', line 9 def initialize(name, args, index, parent, node_builders = []) @name = name.to_s.chomp('!').to_sym @singleton = name[-1] == '!' @args = args @index = index @parent = parent node_builders.each_with_index do |item, i| add_child(item.name, item.args, i, self, item.nodes) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object (protected)
130 131 132 133 134 |
# File 'lib/easydsl/node.rb', line 130 def method_missing(method_symbol, *args, &block) return handle_block(method_symbol, *args, &block) if block_given? return handle_operators(method_symbol, *args) if method_symbol.to_s.end_with?('=', '?', '[]') handle_node(method_symbol, *args, &block) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
7 8 9 |
# File 'lib/easydsl/node.rb', line 7 def args @args end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/easydsl/node.rb', line 6 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/easydsl/node.rb', line 6 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/easydsl/node.rb', line 6 def parent @parent end |
#singleton ⇒ Object (readonly)
Returns the value of attribute singleton.
6 7 8 |
# File 'lib/easydsl/node.rb', line 6 def singleton @singleton end |
Instance Method Details
#all_nodes ⇒ Object
24 25 26 27 28 |
# File 'lib/easydsl/node.rb', line 24 def all_nodes all = [] nodes.each { |k, _v| all += nodes[k] } all.sort! { |a, b| a.index <=> b.index } end |
#define(&block) ⇒ Object
34 35 36 |
# File 'lib/easydsl/node.rb', line 34 def define(&block) add_block(&block) end |
#max_index ⇒ Object
30 31 32 |
# File 'lib/easydsl/node.rb', line 30 def max_index all_nodes.map(&:index).max || 0 end |
#nodes ⇒ Object
20 21 22 |
# File 'lib/easydsl/node.rb', line 20 def nodes @nodes ||= Hash.new { |h, k| h[k] = NodeArray.new } end |