class Tblr::Table
Attributes
headers[R]
rows[R]
Public Class Methods
new(*args)
click to toggle source
# File lib/tblr/table.rb, line 7 def initialize(*args) @headers = args[0] @rows = args[1] end
Public Instance Methods
==(a_table)
click to toggle source
# File lib/tblr/table.rb, line 12 def ==(a_table) headers == a_table.headers && rows == a_table.rows end
[](idx)
click to toggle source
# File lib/tblr/table.rb, line 17 def [](idx) Tblr::Row.new(headers, rows[idx]) end
each() { |row| ... }
click to toggle source
# File lib/tblr/table.rb, line 21 def each @rows.each_with_index do |row, idx| yield(Tblr::Row.new(headers, rows[idx])) end end
group_by(*args, &block)
click to toggle source
# File lib/tblr/table.rb, line 27 def group_by(*args, &block) hash = self.map{|row| row}.group_by(*args, &block) hash.each{|key, data| hash[key] = self.class.new(headers, data.map(&:to_a))} end
size()
click to toggle source
# File lib/tblr/table.rb, line 32 def size rows.size end