Class: CommandBuilderGenerator::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/command_builder_generator/node.rb

Direct Known Subclasses

Command

Instance Method Summary collapse

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

#argsObject



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_nodesObject



10
11
12
# File 'lib/command_builder_generator/node.rb', line 10

def child_nodes
  @child_nodes ||= []
end

#fragmentsObject



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_nameObject



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