|
| 1 | +Squib::DataFrame |
| 2 | +================ |
| 3 | + |
| 4 | +As described in :doc:`/data`, the ``Squib::DataFrame`` is what is returned by Squib's data import methods (:doc:`/dsl/csv` and :doc:`/dsl/xlsx`). |
| 5 | + |
| 6 | +It behaves like a ``Hash`` of ``Arrays``, so acessing an individual column can be done via the square brackets, e.g. ``data['title']``. |
| 7 | + |
| 8 | +Here are some other convenience methods in ``Squib::DataFrame`` |
| 9 | + |
| 10 | +columns become methods |
| 11 | +---------------------- |
| 12 | + |
| 13 | +Through magic of Ruby metaprogramming, every column also becomes a method on the data frame. So these two are equivalent: |
| 14 | + |
| 15 | +.. code-block:: irb |
| 16 | +
|
| 17 | + irb(main):002:0> data = Squib.csv file: 'basic.csv' |
| 18 | + => #<Squib::DataFrame:0x00000003764550 @hash={"h1"=>[1, 3], "h2"=>[2, 4]}> |
| 19 | + irb(main):003:0> data.h1 |
| 20 | + => [1, 3] |
| 21 | + irb(main):004:0> data['h1'] |
| 22 | + => [1, 3] |
| 23 | +
|
| 24 | +#columns |
| 25 | +-------- |
| 26 | + |
| 27 | +Returns an array of the column names in the data frame |
| 28 | + |
| 29 | +#ncolumns |
| 30 | +--------- |
| 31 | + |
| 32 | +Returns the number of columns in the data frame |
| 33 | + |
| 34 | +#col?(name) |
| 35 | +----------- |
| 36 | + |
| 37 | +Returns ``true`` if there is column ``name``. |
| 38 | + |
| 39 | +#row(i) |
| 40 | +------- |
| 41 | + |
| 42 | +Returns a hash of values across all columns in the ``i``th row of the dataframe. Represents a single card. |
| 43 | +
|
| 44 | +#nrows |
| 45 | +------ |
| 46 | +
|
| 47 | +Returns the number of rows the data frame has, computed by the maximum length of any column array. |
| 48 | +
|
| 49 | +#to_json |
| 50 | +-------- |
| 51 | +
|
| 52 | +Returns a ``json`` representation of the entire data frame. |
| 53 | + |
| 54 | +#to_pretty_json |
| 55 | +--------------- |
| 56 | + |
| 57 | +Returns a ``json`` representation of the entire data frame, formatted with indentation for human viewing. |
| 58 | + |
| 59 | +#to_pretty_text |
| 60 | +--------------- |
| 61 | + |
| 62 | +Returns a textual representation of the dataframe that emulates what the information looks like on an individual card. Here's an example: |
| 63 | + |
| 64 | +.. code-block:: text |
| 65 | +
|
| 66 | + ╭------------------------------------╮ |
| 67 | + Name | Mage | |
| 68 | + Cost | 1 | |
| 69 | + Description | You may cast 1 spell per turn | |
| 70 | + Snark | Magic, dude. | |
| 71 | + ╰------------------------------------╯ |
| 72 | + ╭------------------------------------╮ |
| 73 | + Name | Rogue | |
| 74 | + Cost | 2 | |
| 75 | + Description | You always take the first turn. | |
| 76 | + Snark | I like to be sneaky | |
| 77 | + ╰------------------------------------╯ |
| 78 | + ╭------------------------------------╮ |
| 79 | + Name | Warrior | |
| 80 | + Cost | 3 | |
| 81 | + Description | |
| 82 | + Snark | I have a long story to tell to tes | |
| 83 | + | t the word-wrapping ability of pre | |
| 84 | + | tty text formatting. | |
| 85 | + ╰------------------------------------╯ |
0 commit comments