Class: CommandBuilderGenerator::Node
- Inherits:
-
Object
- Object
- CommandBuilderGenerator::Node
- Defined in:
- lib/command_builder_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
6 7 8 |
# File 'lib/command_builder_generator/node.rb', line 6 def initialize(node_def) @node_def = node_def end |
Instance Method Details
#args ⇒ Object
30 31 32 |
# File 'lib/command_builder_generator/node.rb', line 30 def args required_args + optional_args end |
#branch? ⇒ Boolean
14 15 16 |
# File 'lib/command_builder_generator/node.rb', line 14 def branch? !child_nodes.empty? end |
#child_nodes ⇒ Object
10 11 12 |
# File 'lib/command_builder_generator/node.rb', line 10 def child_nodes @child_nodes ||= [] end |
#fragments ⇒ Object
26 27 28 |
# File 'lib/command_builder_generator/node.rb', line 26 def fragments @fragments ||= @node_def.gsub(/ \(.+?\)/, '').gsub(']', ']|').gsub('[', '|[').split('|').compact.map { |f| Fragment.new f } end |
#leaf? ⇒ Boolean
18 19 20 |
# File 'lib/command_builder_generator/node.rb', line 18 def leaf? child_nodes.empty? end |
#node_name ⇒ Object
22 23 24 |
# File 'lib/command_builder_generator/node.rb', line 22 def node_name @node_name ||= node_alias || (starts_with_arg? ? first_arg_name : words_preceding_args) end |