Class: CommandBuilder::CodeGenerator::Node
- Inherits:
-
Object
- Object
- CommandBuilder::CodeGenerator::Node
- Defined in:
- lib/command_builder/code_generator/node.rb
Direct Known Subclasses
Instance Method Summary collapse
- #args ⇒ Object
- #branch? ⇒ Boolean
- #child_nodes ⇒ Object
- #fragments ⇒ Object
-
#initialize(node_def) ⇒ Node
constructor
A new instance of Node.
- #leaf? ⇒ Boolean
- #node_name ⇒ Object
Constructor Details
#initialize(node_def) ⇒ Node
Returns a new instance of Node.
7 8 9 |
# File 'lib/command_builder/code_generator/node.rb', line 7 def initialize(node_def) @node_def = node_def end |
Instance Method Details
#args ⇒ Object
31 32 33 |
# File 'lib/command_builder/code_generator/node.rb', line 31 def args required_args + optional_args end |
#branch? ⇒ Boolean
15 16 17 |
# File 'lib/command_builder/code_generator/node.rb', line 15 def branch? !child_nodes.empty? end |
#child_nodes ⇒ Object
11 12 13 |
# File 'lib/command_builder/code_generator/node.rb', line 11 def child_nodes @child_nodes ||= [] end |
#fragments ⇒ Object
27 28 29 |
# File 'lib/command_builder/code_generator/node.rb', line 27 def fragments @fragments ||= @node_def.gsub(/ \(.+?\)/, '').gsub(']', ']|').gsub('[', '|[').split('|').compact.map { |f| Fragment.new f } end |
#leaf? ⇒ Boolean
19 20 21 |
# File 'lib/command_builder/code_generator/node.rb', line 19 def leaf? child_nodes.empty? end |
#node_name ⇒ Object
23 24 25 |
# File 'lib/command_builder/code_generator/node.rb', line 23 def node_name @node_name ||= node_alias || (starts_with_arg? ? first_arg_name : words_preceding_args) end |