Class | FasterCSV::Table |
In: |
lib/faster_csv.rb
|
Parent: | Object |
A FasterCSV::Table is a two-dimensional data structure for representing CSV documents. Tables allow you to work with the data by row or column, manipulate the data, and even convert the results back to CSV, if needed.
All tables returned by FasterCSV will be constructed from this class, if header row processing is activated.
mode | [R] | The current access mode for indexing and iteration. |
table | [R] | Internal data format used to compare equality. |
Construct a new FasterCSV::Table from array_of_rows, which are expected to be FasterCSV::Row objects. All rows are assumed to have the same headers.
A FasterCSV::Table object supports the following Array methods through delegation:
Adds a new row to the bottom end of this table. You can provide an Array, which will be converted to a FasterCSV::Row (inheriting the table‘s headers()), or a FasterCSV::Row.
This method returns the table for chaining.
In the default mixed mode, this method assigns rows for index access and columns for header access. You can force the index association by first calling by_col!() or by_row!().
Rows may be set to an Array of values (which will inherit the table‘s headers()) or a FasterCSV::Row.
Columns may be set to a single value, which is copied to each row of the column, or an Array of values. Arrays of values are assigned to rows top to bottom in row major order. Excess values are ignored and if the Array does not have a value for each row the extra rows will receive a nil.
Assigning to an existing column or row clobbers the data. Assigning to new columns creates them at the right end of the table.
Returns a duplicate table object, in column mode. This is handy for chaining in a single call without changing the table mode, but be aware that this method can consume a fair amount of memory for bigger data sets.
This method returns the duplicate table for chaining. Don‘t chain destructive methods (like []=()) this way though, since you are working with a duplicate.
Switches the mode of this table to column mode. All calls to indexing and iteration methods will work with columns until the mode is changed again.
This method returns the table and is safe to chain.
Returns a duplicate table object, in mixed mode. This is handy for chaining in a single call without changing the table mode, but be aware that this method can consume a fair amount of memory for bigger data sets.
This method returns the duplicate table for chaining. Don‘t chain destructive methods (like []=()) this way though, since you are working with a duplicate.
Switches the mode of this table to mixed mode. All calls to indexing and iteration methods will use the default intelligent indexing system until the mode is changed again. In mixed mode an index is assumed to be a row reference while anything else is assumed to be column access by headers.
This method returns the table and is safe to chain.
Returns a duplicate table object, in row mode. This is handy for chaining in a single call without changing the table mode, but be aware that this method can consume a fair amount of memory for bigger data sets.
This method returns the duplicate table for chaining. Don‘t chain destructive methods (like []=()) this way though, since you are working with a duplicate.
Switches the mode of this table to row mode. All calls to indexing and iteration methods will work with rows until the mode is changed again.
This method returns the table and is safe to chain.
Removes any column or row for which the block returns true. In the default mixed mode or row mode, iteration is the standard row major walking of rows. In column mode, interation will yield two element tuples containing the column name and an Array of values for that column.
This method returns the table for chaining.
In the default mixed mode or row mode, iteration is the standard row major walking of rows. In column mode, interation will yield two element tuples containing the column name and an Array of values for that column.
This method returns the table for chaining.
A shortcut for appending multiple rows. Equivalent to:
rows.each { |row| self << row }
This method returns the table for chaining.
Returns the table as an Array of Arrays. Headers will be the first row, then all of the field rows will follow.
Returns the table as a complete CSV String. Headers will be listed first, then all of the field rows.
The mixed mode default is to treat a list of indices as row access, returning the rows indicated. Anything else is considered columnar access. For columnar access, the return set has an Array for each row with the values indicated by the headers in each Array. You can force column or row mode using by_col!() or by_row!().
You cannot mix column and row access.