Class: GLI::CommandLineToken

Inherits:
Object
  • Object
show all
Defined in:
lib/gli/command_line_token.rb

Overview

Abstract base class for a logical element of a command line, mostly so that subclasses can have similar initialization and interface

Direct Known Subclasses

Command, CommandLineOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, description, long_description = nil) ⇒ CommandLineToken

:nodoc:



10
11
12
13
14
# File 'lib/gli/command_line_token.rb', line 10

def initialize(names,description,long_description=nil) #:nodoc:
  @description = description
  @long_description = long_description
  @name,@aliases,@names = parse_names(names)
end

Instance Attribute Details

#aliasesObject (readonly)

:nodoc:



6
7
8
# File 'lib/gli/command_line_token.rb', line 6

def aliases
  @aliases
end

#descriptionObject (readonly)

:nodoc:



7
8
9
# File 'lib/gli/command_line_token.rb', line 7

def description
  @description
end

#long_descriptionObject (readonly)

:nodoc:



8
9
10
# File 'lib/gli/command_line_token.rb', line 8

def long_description
  @long_description
end

#nameObject (readonly)

:nodoc:



5
6
7
# File 'lib/gli/command_line_token.rb', line 5

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object

Sort based on primary name



17
18
19
# File 'lib/gli/command_line_token.rb', line 17

def <=>(other)
  self.name.to_s <=> other.name.to_s
end

#names_and_aliasesObject

Array of the name and aliases, as string



22
23
24
# File 'lib/gli/command_line_token.rb', line 22

def names_and_aliases
  [self.name,self.aliases].flatten.compact.map(&:to_s)
end