Method: ArrayHash.pullout
- Defined in:
- lib/rbbt/util/arrayHash.rb
.pullout(hash, pos, options = {}) ⇒ Object
Take an hash of arrays and a position and use the value at that position of the arrays to build a new hash with that value as key, and the original key prepended to the arrays. The options hash accepts the following keys :case_insensitive, which defaults to true, and :index, which indicates that the original key should be the value of the hash entry, instead of the complete array of values.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rbbt/util/arrayHash.rb', line 55 def self.pullout(hash, pos, = {}) index = [:index]; index = false if index.nil? case_insensitive = [:case_insensitive]; case_insensitive = true if case_insensitive.nil? new = {} hash.each{|key,values| code = values[pos].to_s next if code == "" if index list = key else list = [key] + values list.delete_at(pos + 1) end code.split("|").each{|c| c = c.downcase if case_insensitive new[c] = merge_values(new[c], list) } } new = make_case_insensitive new if case_insensitive new end |