class Object

Public Class Methods

copy(target, woff, hoff, source) click to toggle source
# File lib/tafel.rb, line 134
def self.copy(target, woff, hoff, source)

  if table?(source)
    iterate(source) { |x, y, v| target[hoff + y][woff + x] = v }
  else
    target[hoff][woff] = source
  end
end
iterate(table) { |x, y, table[x]| ... } click to toggle source
# File lib/tafel.rb, line 143
def self.iterate(table)

  table.first.size.times do |x|
    table.size.times do |y|
      yield(x, y, table[y][x])
    end
  end if table.any?
end
narrow_class(x) click to toggle source
# File lib/tafel.rb, line 152
def self.narrow_class(x)

  return Array if x.is_a?(Array)
  return Hash if x.is_a?(Hash)
  nil
end
to_h_array_hash(a) click to toggle source
# File lib/tafel.rb, line 176
def self.to_h_array_hash(a)

  keys = a.inject([]) { |ks, h| ks.concat(h.keys) }.uniq
  table = [ keys ]

  a.each do |h|
    table << keys.inject([]) { |row, key| row << h[key]; row }
  end

  table
end
to_h_hash(h) click to toggle source
# File lib/tafel.rb, line 171
def self.to_h_hash(h)

  [ h.keys, h.inject([]) { |a, (k, v)| a << v; a } ]
end
to_h_hash_hash(h) click to toggle source
# File lib/tafel.rb, line 159
def self.to_h_hash_hash(h)

  keys = h.values.inject([ :key ]) { |ks, v| ks.concat(v.keys) }.uniq
  table = [ keys ]

  h.each do |k, v|
    table << keys[1..-1].inject([ k ]) { |row, key| row << v[key]; row }
  end

  table
end