Class: XOptionParser::Switch::SummarizeArgument
- Inherits:
-
XOptionParser::Switch
- Object
- OptionParser::Switch
- XOptionParser::Switch
- XOptionParser::Switch::SummarizeArgument
- Defined in:
- lib/xoptparse.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arg_parameters ⇒ Object
readonly
Returns the value of attribute arg_parameters.
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
-
#initialize ⇒ SummarizeArgument
constructor
A new instance of SummarizeArgument.
- #match_nonswitch? ⇒ Boolean
- #parse(_arg, _argv) ⇒ Object
- #summarize ⇒ Object
- #switch_name ⇒ Object
Constructor Details
#initialize ⇒ SummarizeArgument
Returns a new instance of SummarizeArgument.
179 180 181 182 183 184 185 186 |
# File 'lib/xoptparse.rb', line 179 def initialize(*) super @ranges = [] @arg_parameters = arg.scan(/\[\s*(.*?)\s*\]|(\S+)/).map do |opt, req| name = opt || req [name.sub(/\s*\.\.\.$/, ''), opt ? :opt : :req, name.end_with?('...') ? :rest : nil] end end |
Instance Attribute Details
#arg_parameters ⇒ Object (readonly)
Returns the value of attribute arg_parameters.
177 178 179 |
# File 'lib/xoptparse.rb', line 177 def arg_parameters @arg_parameters end |
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
176 177 178 |
# File 'lib/xoptparse.rb', line 176 def ranges @ranges end |
Instance Method Details
#match_nonswitch? ⇒ Boolean
201 202 203 |
# File 'lib/xoptparse.rb', line 201 def match_nonswitch?(*) nil end |
#parse(_arg, _argv) ⇒ Object
209 210 211 |
# File 'lib/xoptparse.rb', line 209 def parse(_arg, _argv) raise XOptionParser::InvalidOption end |
#summarize ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/xoptparse.rb', line 188 def summarize(*) original_arg = arg @short = arg_parameters.map do |name, type, rest| var = "#{name}#{rest ? '...' : ''}" type == :req ? var : "[#{var}]" end @arg = nil res = super @arg = original_arg @short = nil res end |
#switch_name ⇒ Object
205 206 207 |
# File 'lib/xoptparse.rb', line 205 def switch_name arg_parameters.first.first end |