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_symbol(symbol) ⇒ Object
Self extract symbol.
Instance Method Details
#extract_color ⇒ Object
Self extract color.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/lib/utils.rb', line 291 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.
271 272 273 274 275 |
# File 'lib/lib/utils.rb', line 271 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 ]
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/lib/utils.rb', line 334 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 += count self.delete(argument) end end end end return result end |
#extract_symbol(symbol) ⇒ Object
Self extract symbol.
280 281 282 283 284 285 286 287 |
# File 'lib/lib/utils.rb', line 280 def extract_symbol symbol status = false if self.include? symbol status = true self.delete(symbol) end return status end |