Class: CommandLineParser
- Inherits:
-
Object
- Object
- CommandLineParser
- Defined in:
- lib/lucie/command_line_parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #args ⇒ Object
- #has_arg?(option) ⇒ Boolean
- #has_option?(option) ⇒ Boolean
-
#initialize(parameters) ⇒ CommandLineParser
constructor
A new instance of CommandLineParser.
- #pair(short, long) ⇒ Object
- #shift ⇒ Object
Constructor Details
#initialize(parameters) ⇒ CommandLineParser
Returns a new instance of CommandLineParser.
7 8 9 10 11 12 13 14 |
# File 'lib/lucie/command_line_parser.rb', line 7 def initialize(parameters) @params_str = parameters.class == Array ? parameters.join(" ") : parameters @options = {} @options[:args] = [] @latest_option = nil () end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/lucie/command_line_parser.rb', line 5 def @options end |
Instance Method Details
#[](name) ⇒ Object
16 17 18 |
# File 'lib/lucie/command_line_parser.rb', line 16 def [](name) @options[name] end |
#args ⇒ Object
43 44 45 |
# File 'lib/lucie/command_line_parser.rb', line 43 def args @options[:args].dup end |
#has_arg?(option) ⇒ Boolean
39 40 41 |
# File 'lib/lucie/command_line_parser.rb', line 39 def has_arg?(option) @options[:args].include?(option) end |
#has_option?(option) ⇒ Boolean
35 36 37 |
# File 'lib/lucie/command_line_parser.rb', line 35 def has_option?(option) @options[remove_dashes(option).to_sym] || false end |
#pair(short, long) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lucie/command_line_parser.rb', line 24 def pair(short, long) short_p = remove_dashes(short).to_sym long_p = remove_dashes(long).to_sym if @options[short_p].class == String @options[long_p] = @options[short_p] else @options[short_p] = @options[long_p] end end |
#shift ⇒ Object
20 21 22 |
# File 'lib/lucie/command_line_parser.rb', line 20 def shift @options[:args].shift end |