Class: Perennial::ArgumentParser
- Defined in:
- lib/perennial/argument_parser.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(array) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #parse! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(array) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
8 9 10 11 12 |
# File 'lib/perennial/argument_parser.rb', line 8 def initialize(array) @raw_arguments = array.dup @arguments = [] @results = {} end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/perennial/argument_parser.rb', line 6 def arguments @arguments end |
Class Method Details
.parse(args = ARGV) ⇒ Object
30 31 32 33 34 |
# File 'lib/perennial/argument_parser.rb', line 30 def self.parse(args = ARGV) parser = self.new(args) parser.parse! return parser.arguments, parser.to_hash end |
Instance Method Details
#parse! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/perennial/argument_parser.rb', line 18 def parse! while !@raw_arguments.empty? current = @raw_arguments.shift if option?(current) process_option(current, @raw_arguments.first) else @arguments.push current end end return nil end |
#to_hash ⇒ Object
14 15 16 |
# File 'lib/perennial/argument_parser.rb', line 14 def to_hash @results ||= {} end |