Method: TableData::Table#initialize
- Defined in:
- lib/tabledata/table.rb
#initialize(data = [], options = nil) ⇒ Table
Returns a new instance of Table.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tabledata/table.rb', line 57 def initialize(data=[], =nil) = ? self.class::DefaultOptions.merge() : self.class::DefaultOptions.dup column_count = data.first ? data.first.size : 0 @has_header = .delete(:has_header) ? true : false @data = data @rows = data.map.with_index { |row, index| raise InvalidColumnCount, "Invalid column count in row #{index} (#{column_count} expected, but has #{row.size})" if index > 0 && row.size != column_count raise ArgumentError, "Row must be provided as Array, but got #{row.class} in row #{index}" unless row.is_a?(Array) Row.new(self, index, row) } @column_count = nil @header_columns = nil @accessor_columns = {} @column_accessors = {} @accessors = [].freeze self.accessors = .delete(:accessors) end |