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
- #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.
5 6 7 8 9 10 11 |
# File 'lib/lucie/command_line_parser.rb', line 5 def initialize(parameters) @params_str = parameters.class == Array ? parameters.join(" ") : parameters @options = {} @latest_option = nil () end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/lucie/command_line_parser.rb', line 3 def @options end |
Instance Method Details
#[](name) ⇒ Object
13 14 15 |
# File 'lib/lucie/command_line_parser.rb', line 13 def [](name) @options[name] end |
#has_arg?(option) ⇒ Boolean
36 37 38 |
# File 'lib/lucie/command_line_parser.rb', line 36 def has_arg?(option) @options[:args].include?(option) end |
#has_option?(option) ⇒ Boolean
32 33 34 |
# File 'lib/lucie/command_line_parser.rb', line 32 def has_option?(option) @options[remove_dashes(option).to_sym] || false end |
#pair(short, long) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lucie/command_line_parser.rb', line 21 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
17 18 19 |
# File 'lib/lucie/command_line_parser.rb', line 17 def shift @options[:args].shift end |