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).
-
#eql?(rhs) ⇒ Boolean
:nodoc:.
-
#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
extras-
An application-defined additional parameter. If
nil, it is assigned an emptyHash
72 73 74 75 76 77 78 |
# File 'lib/clasp/specifications.rb', line 72 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
83 84 85 |
# File 'lib/clasp/specifications.rb', line 83 def aliases @aliases end |
#extras ⇒ Object (readonly)
The flag’s extras
87 88 89 |
# File 'lib/clasp/specifications.rb', line 87 def extras @extras end |
#help ⇒ Object (readonly)
The flag’s help string
85 86 87 |
# File 'lib/clasp/specifications.rb', line 85 def help @help end |
#name ⇒ Object (readonly)
The flag’s name string
81 82 83 |
# File 'lib/clasp/specifications.rb', line 81 def name @name end |
Class Method Details
.Help(extras = nil) ⇒ Object
An instance of FlagSpecification that provides default ‘–help’ information
135 136 137 138 139 140 141 142 |
# File 'lib/clasp/specifications.rb', line 135 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
145 146 147 148 149 150 151 152 |
# File 'lib/clasp/specifications.rb', line 145 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)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/clasp/specifications.rb', line 115 def == rhs case rhs when self.class return self.eql? rhs when String return name == rhs else false end end |
#eql?(rhs) ⇒ Boolean
:nodoc:
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/clasp/specifications.rb', line 95 def eql? rhs # :nodoc: case rhs when self.class ; else return false end return false unless name == rhs.name return false unless aliases == rhs.aliases return false unless help == rhs.help return false unless extras == rhs.extras return true end |
#to_s ⇒ Object
String form of the flag
90 91 92 93 |
# File 'lib/clasp/specifications.rb', line 90 def to_s "{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}" end |