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, args = {}) ⇒ Object
-
#extract_symbol(symbol) ⇒ Object
Self extract symbol.
Instance Method Details
#extract_color ⇒ Object
Self extract color.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lib/array.rb', line 24 def extract_color each do |argument| if argument.symbol? && String.colors.include?(argument) color = argument delete(argument) return color elsif argument.string? && argument.start_with?(':') color_candidate = argument.gsub(':', '').to_sym color = color_candidate if String.colors.include? color_candidate delete(argument) return color end end :default end |
#extract_first ⇒ Object
Self pop first element.
4 5 6 7 8 |
# File 'lib/lib/array.rb', line 4 def extract_first first = self[0] delete_at(0) 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 ]
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/lib/array.rb', line 56 def extract_option(option, single = true) if single result = false if include? option index = self.index(option) delete_at(index) result = true end else result = 0 each do |argument| next unless argument.to_s.start_with? option # puts "'#{option}' '#{argument}' #{argument.start_with? option} \n" search_char = option.sub('-', '') aux_string = argument.to_s.sub('-', '') count = argument.to_s.count(search_char) if count == aux_string.size result += count # self.delete(argument) end end end result end |
#extract_option_value(option, args = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/lib/array.rb', line 81 def extract_option_value(option, args = {}) args[:multiple] = false if args[:multiple].nil? args[:separator] = '=' if args[:separator].nil? result = false if args[:multiple] multiple_value = [] while include? option index = self.index(option) delete_at(index) result = true value = at(index) multiple_value << at(index).split(args[:separator]).first multiple_value << at(index).split(args[:separator]).last delete_at(index) end return [result, multiple_value] else value = nil while include? option index = self.index(option) delete_at(index) result = true value = at(index) delete_at(index) end return [result, value] end end |
#extract_symbol(symbol) ⇒ Object
Self extract symbol.
13 14 15 16 17 18 19 20 |
# File 'lib/lib/array.rb', line 13 def extract_symbol(symbol) status = false if include? symbol status = true delete(symbol) end status end |