Class: Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nub/commander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, desc, nodes: [], examples: nil) ⇒ Command

Create a new command

Parameters:

  • name (String)

    command name used on command line

  • desc (String)

    the command’s description

  • nodes (String) (defaults to: [])

    the command’s description

  • examples (String) (defaults to: nil)

    the command’s examples



113
114
115
116
117
118
119
# File 'lib/nub/commander.rb', line 113

def initialize(name, desc, nodes:[], examples:nil)
  @name = name
  @desc = desc
  @nodes = nodes
  @examples = examples
  @help = ""
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



103
104
105
# File 'lib/nub/commander.rb', line 103

def desc
  @desc
end

#examplesObject

Returns the value of attribute examples.



106
107
108
# File 'lib/nub/commander.rb', line 106

def examples
  @examples
end

#helpObject

Returns the value of attribute help.



105
106
107
# File 'lib/nub/commander.rb', line 105

def help
  @help
end

#nameObject (readonly)

Returns the value of attribute name.



102
103
104
# File 'lib/nub/commander.rb', line 102

def name
  @name
end

#nodesObject

Returns the value of attribute nodes.



104
105
106
# File 'lib/nub/commander.rb', line 104

def nodes
  @nodes
end

Instance Method Details

#to_s(level: 0) ⇒ Object

Return a human readable string of this object

Parameters:

  • level (Integer) (defaults to: 0)

    level to indent



129
130
131
132
133
134
135
# File 'lib/nub/commander.rb', line 129

def to_s(level:0)
  str = "#{" " * level * 2}Command => name:#{@name}, desc:'#{@desc}'"
  @nodes.each{|x|
    str += "\n#{x.to_s(level: level + 1)}"
  }
  return str
end

#to_symObject

Get a symbol representing the command



123
124
125
# File 'lib/nub/commander.rb', line 123

def to_sym
  return @name.gsub('-', '_').to_sym
end