Class: RProgram::NonOption
- Inherits:
-
Object
- Object
- RProgram::NonOption
- Defined in:
- lib/rprogram/non_option.rb
Instance Attribute Summary collapse
-
#multiple ⇒ Object
readonly
Can the argument be specified multiple times.
-
#name ⇒ Object
readonly
Name of the argument(s).
Instance Method Summary collapse
-
#arguments(value) ⇒ Array
Formats the arguments for the non-option.
-
#initialize(options = {}) ⇒ NonOption
constructor
Creates a new NonOption object.
-
#leading? ⇒ true, false
Determines whether the non-option's arguments are leading.
-
#tailing? ⇒ true, false
Determines whether the non-option's arguments are tailing.
Constructor Details
#initialize(options = {}) ⇒ NonOption
Creates a new NonOption object.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rprogram/non_option.rb', line 28 def initialize(={}) @name = [:name] @tailing = if [:leading] !([:leading]) elsif [:tailing] [:tailing] else true end @multiple = ([:multiple] || false) end |
Instance Attribute Details
#multiple ⇒ Object (readonly)
Can the argument be specified multiple times
8 9 10 |
# File 'lib/rprogram/non_option.rb', line 8 def multiple @multiple end |
#name ⇒ Object (readonly)
Name of the argument(s)
5 6 7 |
# File 'lib/rprogram/non_option.rb', line 5 def name @name end |
Instance Method Details
#arguments(value) ⇒ Array
Formats the arguments for the non-option.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rprogram/non_option.rb', line 71 def arguments(value) return [] unless value if value.kind_of?(Hash) value = value.map do |key,sub_value| if sub_value == true key.to_s elsif sub_value "#{key}=#{sub_value}" end end elsif value.kind_of?(Array) value = value.flatten else value = [value] end return value.compact end |
#leading? ⇒ true, false
Determines whether the non-option's arguments are leading.
58 59 60 |
# File 'lib/rprogram/non_option.rb', line 58 def leading? !(@tailing) end |
#tailing? ⇒ true, false
Determines whether the non-option's arguments are tailing.
48 49 50 |
# File 'lib/rprogram/non_option.rb', line 48 def tailing? @tailing == true end |