Class: XOptionParser::Switch::SimpleArgument
- Inherits:
-
SummarizeArgument
- Object
- OptionParser::Switch
- XOptionParser::Switch
- SummarizeArgument
- XOptionParser::Switch::SimpleArgument
- Defined in:
- lib/xoptparse.rb
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Attributes inherited from SummarizeArgument
Instance Method Summary collapse
- #add_banner(to) ⇒ Object
-
#initialize ⇒ SimpleArgument
constructor
A new instance of SimpleArgument.
- #parse(arg, argv) ⇒ Object
Methods inherited from SummarizeArgument
#match_nonswitch?, #summarize, #switch_name
Constructor Details
#initialize ⇒ SimpleArgument
198 199 200 201 202 203 |
# File 'lib/xoptparse.rb', line 198 def initialize(*) super @ranges = arg_parameters.map do |_name, type, rest| (type == :req ? 1 : 0)..(rest == :rest ? nil : 1) end end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
196 197 198 |
# File 'lib/xoptparse.rb', line 196 def ranges @ranges end |
Instance Method Details
#add_banner(to) ⇒ Object
205 206 207 |
# File 'lib/xoptparse.rb', line 205 def (to) to << " #{arg}" end |
#parse(arg, argv) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/xoptparse.rb', line 209 def parse(arg, argv) case ranges.size when 0 super(arg, argv) when 1 unless arg raise XOptionParser::MissingArgument if argv.empty? arg = argv.shift end arg = [arg] if ranges.first.end.nil? conv_arg(*parse_arg(arg, &method(:raise))) else raise XOptionParser::InvalidOption end end |