Module: Crosscounter::Util

Defined in:
lib/crosscounter/util.rb

Constant Summary collapse

@@tuples =
{}

Class Method Summary collapse

Class Method Details

.stringify_all(array) ⇒ Object



13
14
15
# File 'lib/crosscounter/util.rb', line 13

def self.stringify_all(array)
  array.map { |object| Crosscounter::Util.stringify_keys(object) }
end

.stringify_keys(hash) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/crosscounter/util.rb', line 5

def self.stringify_keys(hash)
  hash.keys.each do |key|
    hash[key.to_s] = hash.delete(key)
  end

  hash
end

.tuplize(hash) ⇒ Object



17
18
19
20
21
# File 'lib/crosscounter/util.rb', line 17

def self.tuplize(hash)
  @@tuples[hash] ||= hash.flat_map do |tuple|
    tuple.last.map { |value| [tuple.first.to_s, value] }
  end
end