Class: CommandBuilder::CodeGenerator::Node

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

Direct Known Subclasses

Command

Instance Method Summary collapse

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

#argsObject



31
32
33
# File 'lib/command_builder/code_generator/node.rb', line 31

def args
  required_args + optional_args
end

#branch?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/command_builder/code_generator/node.rb', line 15

def branch?
  !child_nodes.empty?
end

#child_nodesObject



11
12
13
# File 'lib/command_builder/code_generator/node.rb', line 11

def child_nodes
  @child_nodes ||= []
end

#fragmentsObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/command_builder/code_generator/node.rb', line 19

def leaf?
  child_nodes.empty?
end

#node_nameObject



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