class TableData::Column
Attributes
index[R]
table[R]
Public Class Methods
new(table, index)
click to toggle source
# File lib/tabledata/column.rb, line 10 def initialize(table, index) @table = table @index = index end
Public Instance Methods
[](*args)
click to toggle source
# File lib/tabledata/column.rb, line 23 def [](*args) rows = @table.rows[*args] if rows.is_a?(Array) # slice rows.map { |row| row.at(@index) } else # single row rows.at(@index) end end
accessor()
click to toggle source
# File lib/tabledata/column.rb, line 19 def accessor @table.column_accessor(@index) end
each() { |at| ... }
click to toggle source
# File lib/tabledata/column.rb, line 33 def each return enum_for(__method__) unless block_given? @table.each do |row| yield row.at(@index) end end
header()
click to toggle source
# File lib/tabledata/column.rb, line 15 def header @table.column_header(@index) end
to_a(include_header=true)
click to toggle source
# File lib/tabledata/column.rb, line 41 def to_a(include_header=true) data = @table.data.transpose[@index] include_header || !@table.headers? ? data : data[1..-1] end