Class: Hieracles::Optparse
- Inherits:
-
Object
- Object
- Hieracles::Optparse
- Defined in:
- lib/hieracles/optparse.rb
Direct Known Subclasses
Hieracles::Options::Hc, Hieracles::Options::Hieracles, Hieracles::Options::Ppdb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #available_options ⇒ Object
-
#initialize(array) ⇒ Optparse
constructor
A new instance of Optparse.
- #optionkeys ⇒ Object
Constructor Details
#initialize(array) ⇒ Optparse
Returns a new instance of Optparse.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hieracles/optparse.rb', line 11 def initialize(array) @options = {} @payload = [] ok = optionkeys while x = array.shift if x[0] == '-' found = ok[x[/[a-z][-_a-z]*$/]] if found if found[:has_args] @options[found[:var]] = array.shift else @options[found[:var]] = true end else array.shift end else @payload << x end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/hieracles/optparse.rb', line 5 def @options end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/hieracles/optparse.rb', line 5 def payload @payload end |
Instance Method Details
#available_options ⇒ Object
7 8 9 |
# File 'lib/hieracles/optparse.rb', line 7 def {} end |
#optionkeys ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/hieracles/optparse.rb', line 33 def optionkeys back = {} .each do |k, v| v[:aliases].each do |a| back[a] = { var: k, has_args: v[:has_arg] } end end back end |