Class: Hieracles::Optparse
- Inherits:
-
Object
- Object
- Hieracles::Optparse
- Defined in:
- lib/hieracles/optparse.rb
Constant Summary collapse
- OPTIONS =
{ config: { has_arg: true, aliases: ['c', 'conf', 'config'] }, format: { has_arg: true, aliases: ['f', 'format'] }, params: { has_arg: true, aliases: ['p', 'params'] }, hierafile: { has_arg: true, aliases: ['h', 'hierafile'] }, basepath: { has_arg: true, aliases: ['b', 'basepath'] }, encpath: { has_arg: true, aliases: ['e', 'encpath'] } }
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
-
#initialize(array) ⇒ Optparse
constructor
A new instance of Optparse.
- #optionkeys ⇒ Object
Constructor Details
#initialize(array) ⇒ Optparse
Returns a new instance of Optparse.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hieracles/optparse.rb', line 34 def initialize(array) = {} @payload = [] ok = optionkeys while x = array.shift if x[0] == '-' if ok[x[/[a-z][-_a-z]*$/]] [ok[x[/[a-z][-_a-z]*$/]]] = array.shift 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 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
#optionkeys ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/hieracles/optparse.rb', line 51 def optionkeys back = {} OPTIONS.each do |k, v| v[:aliases].each do |a| back[a] = k end end back end |