class Turnip::Table
Attributes
raw[R]
to_a[R]
Public Class Methods
new(raw)
click to toggle source
# File lib/turnip/table.rb, line 20 def initialize(raw) @raw = raw end
Public Instance Methods
each() { |row| ... }
click to toggle source
# File lib/turnip/table.rb, line 45 def each raw.each { |row| yield(row) } end
hashes()
click to toggle source
# File lib/turnip/table.rb, line 32 def hashes rows.map { |row| Hash[headers.zip(row)] } end
headers()
click to toggle source
# File lib/turnip/table.rb, line 24 def headers raw.first end
map_column!(name, strict = true) { |row| ... }
click to toggle source
# File lib/turnip/table.rb, line 49 def map_column!(name, strict = true) index = headers.index(name.to_s) if index.nil? raise ColumnNotExist.new(name) if strict else rows.each { |row| row[index] = yield(row[index]) } end end
rows()
click to toggle source
# File lib/turnip/table.rb, line 28 def rows raw.drop(1) end
rows_hash()
click to toggle source
# File lib/turnip/table.rb, line 36 def rows_hash raise WidthMismatch.new(2, width) unless width == 2 transpose.hashes.first end
transpose()
click to toggle source
# File lib/turnip/table.rb, line 41 def transpose self.class.new(raw.transpose) end
Private Instance Methods
width()
click to toggle source
# File lib/turnip/table.rb, line 60 def width raw[0].size end