Class: Clip::Option
- Inherits:
-
Object
- Object
- Clip::Option
- Defined in:
- lib/clip.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#description ⇒ Object
Returns the value of attribute description.
-
#long ⇒ Object
Returns the value of attribute long.
-
#multi ⇒ Object
Returns the value of attribute multi.
-
#required ⇒ Object
Returns the value of attribute required.
-
#short ⇒ Object
Returns the value of attribute short.
Instance Method Summary collapse
- #has_default? ⇒ Boolean
-
#initialize(short, long, options) ⇒ Option
constructor
A new instance of Option.
- #multi? ⇒ Boolean
- #process(parser, value) ⇒ Object
- #required? ⇒ Boolean
- #usage ⇒ Object
Constructor Details
#initialize(short, long, options) ⇒ Option
Returns a new instance of Option.
344 345 346 347 348 349 350 351 |
# File 'lib/clip.rb', line 344 def initialize(short, long, ) @short = short @long = long @description = [:desc] || "" @default = [:default] @required = [:required] @multi = [:multi] end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
342 343 344 |
# File 'lib/clip.rb', line 342 def default @default end |
#description ⇒ Object
Returns the value of attribute description.
342 343 344 |
# File 'lib/clip.rb', line 342 def description @description end |
#long ⇒ Object
Returns the value of attribute long.
342 343 344 |
# File 'lib/clip.rb', line 342 def long @long end |
#multi ⇒ Object
Returns the value of attribute multi.
342 343 344 |
# File 'lib/clip.rb', line 342 def multi @multi end |
#required ⇒ Object
Returns the value of attribute required.
342 343 344 |
# File 'lib/clip.rb', line 342 def required @required end |
#short ⇒ Object
Returns the value of attribute short.
342 343 344 |
# File 'lib/clip.rb', line 342 def short @short end |
Instance Method Details
#has_default? ⇒ Boolean
367 368 369 |
# File 'lib/clip.rb', line 367 def has_default? not @default.nil? end |
#multi? ⇒ Boolean
371 372 373 |
# File 'lib/clip.rb', line 371 def multi? @multi == true end |
#process(parser, value) ⇒ Object
353 354 355 356 357 358 359 360 361 |
# File 'lib/clip.rb', line 353 def process(parser, value) if @multi current = parser.send(@long) || [] current.concat(value.split(',')) parser.send("#{@long}=".to_sym, current) else parser.send("#{@long}=".to_sym, value) end end |
#required? ⇒ Boolean
363 364 365 |
# File 'lib/clip.rb', line 363 def required? @required == true end |
#usage ⇒ Object
375 376 377 378 379 380 381 382 383 |
# File 'lib/clip.rb', line 375 def usage out = sprintf('-%-2s --%-10s %s', @short, @long.to_s.gsub('_', '-').to_sym, @description) out << " (defaults to '#{@default}')" if @default out << " REQUIRED" if @required out end |