Class: Aargvark::Argument
- Inherits:
-
Object
- Object
- Aargvark::Argument
- Defined in:
- lib/aargvark.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#letter ⇒ Object
Returns the value of attribute letter.
-
#noarg ⇒ Object
Returns the value of attribute noarg.
-
#required ⇒ Object
Returns the value of attribute required.
-
#sub_args ⇒ Object
Returns the value of attribute sub_args.
-
#subarg_range ⇒ Object
Returns the value of attribute subarg_range.
Instance Method Summary collapse
-
#initialize(arg_array) ⇒ Argument
constructor
A new instance of Argument.
Constructor Details
#initialize(arg_array) ⇒ Argument
Returns a new instance of Argument.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/aargvark.rb', line 156 def initialize (arg_array) @sub_args = [] @subarg_range = [0,0] if arg_array.class != Array if arg_array.class == String if arg_array.is_arg? @letter = arg_array end else raise ArgumentError, "\"#{arg_array}\" is not a valid argument. Arguments and the details" + " thereof must be entered as an Array in the format:" + "[\"-n\", \"--argument-alias\", [true/false, :string/:integer/:float], etc...]" end else if arg_array[0].is_arg? @letter = arg_array[0] elsif arg_array[0].is_noarg? @noarg = true else raise ArgumentError, "The first item in each Argument array must be either a lowercase letter preceded by" + " a hyphen or the symbol :noarg. Please go back and make sure that your argument arrays conform to" + " these standards." end end if arg_array.size > 1 #If the second item in an argument array is an alias, set the alias for the #argument as that value. if arg_array[1].is_alias? @alias = arg_array[1] end if arg_array[1] == :required || arg_array[2] == :required @required = true else @required = false end = 1 if @alias += 1 end if @required += 1 end .upto(arg_array.size - 1) do |x| if arg_array[x]. @sub_args << arg_array[x] end end end @sub_args.each do || @subarg_range[0] += 1 if .to_s == "true" @subarg_range[1] += 1 end end |
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def alias @alias end |
#letter ⇒ Object
Returns the value of attribute letter.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def letter @letter end |
#noarg ⇒ Object
Returns the value of attribute noarg.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def noarg @noarg end |
#required ⇒ Object
Returns the value of attribute required.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def required @required end |
#sub_args ⇒ Object
Returns the value of attribute sub_args.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def sub_args @sub_args end |
#subarg_range ⇒ Object
Returns the value of attribute subarg_range.
154 155 156 |
# File 'lib/aargvark.rb', line 154 def @subarg_range end |