Class: CLASP::FlagSpecification
- Inherits:
-
Object
- Object
- CLASP::FlagSpecification
- Defined in:
- lib/clasp/specifications.rb
Overview
A class that represents the specification for a command-line flag
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
The flag’s aliases array.
-
#extras ⇒ Object
readonly
The flag’s extras.
-
#help ⇒ Object
readonly
The flag’s help string.
-
#name ⇒ Object
readonly
The flag’s name string.
Class Method Summary collapse
-
.Help(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information.
-
.Version(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–version’ information.
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
Compares instance against another FlagSpecification or against a name (String).
-
#initialize(name, aliases, help, extras = nil) ⇒ FlagSpecification
constructor
Creates a FlagSpecification instance from the given name, aliases, and help.
-
#to_s ⇒ Object
String form of the flag.
Constructor Details
#initialize(name, aliases, help, extras = nil) ⇒ FlagSpecification
Creates a FlagSpecification instance from the given name, aliases, and help
Signature
-
Parameters
-
name(String) The name, or long-form, of the flag -
aliases(Array) 0 or more strings specifying short-form or option-value aliases -
help(String) The help string, which may benil -
extrasAn application-defined additional parameter. Ifnil, it is assigned an emptyHash
-
NOTE: Users should prefer the CLASP::Flag() method
74 75 76 77 78 79 80 |
# File 'lib/clasp/specifications.rb', line 74 def initialize(name, aliases, help, extras = nil) @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @extras = extras || {} end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
The flag’s aliases array
85 86 87 |
# File 'lib/clasp/specifications.rb', line 85 def aliases @aliases end |
#extras ⇒ Object (readonly)
The flag’s extras
89 90 91 |
# File 'lib/clasp/specifications.rb', line 89 def extras @extras end |
#help ⇒ Object (readonly)
The flag’s help string
87 88 89 |
# File 'lib/clasp/specifications.rb', line 87 def help @help end |
#name ⇒ Object (readonly)
The flag’s name string
83 84 85 |
# File 'lib/clasp/specifications.rb', line 83 def name @name end |
Class Method Details
.Help(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information
138 139 140 141 142 143 144 145 |
# File 'lib/clasp/specifications.rb', line 138 def self.Help(extras = nil) h = @@Help_ return self.new(h.name, h.aliases, h.help, extras) if extras h end |
.Version(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–version’ information
148 149 150 151 152 153 154 155 |
# File 'lib/clasp/specifications.rb', line 148 def self.Version(extras = nil) h = @@Version_ return self.new(h.name, h.aliases, h.help, extras) if extras h end |
Instance Method Details
#==(rhs) ⇒ Object
Compares instance against another FlagSpecification or against a name (String)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/clasp/specifications.rb', line 118 def == rhs case rhs when self.class return self.eql? rhs when String return name == rhs else false end end |
#to_s ⇒ Object
String form of the flag
92 93 94 95 |
# File 'lib/clasp/specifications.rb', line 92 def to_s "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}" end |