Class: LilUtils::CLI::NumberedOption

Inherits:
Option
  • Object
show all
Defined in:
lib/lilutils/cli/cli.rb

Overview

An Option with a name and a positive number used to identify its selection. This is useful when two Options start with the same character (e.g. “Chai” and “Coffee”)

Instance Attribute Summary collapse

Attributes inherited from Option

#name

Instance Method Summary collapse

Methods inherited from Option

#key

Constructor Details

#initialize(number, name) ⇒ NumberedOption

Returns a new instance of NumberedOption.



84
85
86
87
# File 'lib/lilutils/cli/cli.rb', line 84

def initialize(number, name)
  super(name)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



82
83
84
# File 'lib/lilutils/cli/cli.rb', line 82

def number
  @number
end

Instance Method Details

#==(other) ⇒ Object

redefine



90
91
92
# File 'lib/lilutils/cli/cli.rb', line 90

def ==(other)
  @name == other.name && @number == other.number
end

#as_defaultObject

redefine



100
101
102
# File 'lib/lilutils/cli/cli.rb', line 100

def as_default
  "*#{@name} (#{@number})*"
end

#as_non_defaultObject

redefine



105
106
107
# File 'lib/lilutils/cli/cli.rb', line 105

def as_non_default
  "#{@name} (#{@number})"
end

#to_sObject



109
110
111
# File 'lib/lilutils/cli/cli.rb', line 109

def to_s
  "#{@name}, #{number}"
end

#valid_response(r) ⇒ Object

redefine



95
96
97
# File 'lib/lilutils/cli/cli.rb', line 95

def valid_response(r)
  @number.to_s == r
end