Class: Array
Instance Method Summary collapse
-
#extract_color ⇒ Object
Self extract color.
-
#extract_first ⇒ Object
Self pop first element.
-
#extract_option(option, single = true) ⇒ Object
Self extract option.
- #extract_option_value(option) ⇒ Object
-
#extract_symbol(symbol) ⇒ Object
Self extract symbol.
Instance Method Details
#extract_color ⇒ Object
Self extract color.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/lib/utils.rb', line 305 def extract_color colors = String.colors color = :default self.each do |argument| if argument.symbol? if colors.include? argument color = argument self.delete(argument) return color end else if argument.string? if argument.start_with? ':' color_candidate = argument.gsub(':','').to_sym color = color_candidate if colors.include? color_candidate self.delete(argument) return color end end end end return color end |
#extract_first ⇒ Object
Self pop first element.
285 286 287 288 289 |
# File 'lib/lib/utils.rb', line 285 def extract_first first = self[0] self.delete_at(0) return first end |
#extract_option(option, single = true) ⇒ Object
Self extract option. Sample args = [xxx -x -vvv -c -vcv -v2 -vvvvv -s :json :yellow :red] args.extract_option '-x' => true args.extract_option '-f' => false args.extract_option '-v', false => 8 args.extract_symbol :json => true args.extract_symbol :yaml => false args.extract_color => :yellow args.extract_color => red args => [-c -vcv -v2 -s ]
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/lib/utils.rb', line 348 def extract_option option, single = true if single result = false if self.include? option index = self.index(option) self.delete_at(index) result = true end else result = 0 self.each do |argument| if argument.start_with? option #puts "'#{option}' '#{argument}' #{argument.start_with? option} \n" search_char = option.sub('-','') aux_string = argument.sub('-','') count = argument.count(search_char) if (count == aux_string.size) result = result + count #self.delete(argument) end end end end return result end |
#extract_option_value(option) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/lib/utils.rb', line 375 def extract_option_value option result = false value = nil if self.include? option index = self.index(option) self.delete_at(index) result = true value = self.at(index) self.delete_at(index) end return [result, value] end |
#extract_symbol(symbol) ⇒ Object
Self extract symbol.
294 295 296 297 298 299 300 301 |
# File 'lib/lib/utils.rb', line 294 def extract_symbol symbol status = false if self.include? symbol status = true self.delete(symbol) end return status end |