fat_table 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/README.md +2168 -0
- data/README.org +230 -212
- data/TODO.org +7 -0
- data/bin/ft_console +82 -79
- data/fat_table.gemspec +45 -43
- data/lib/fat_table.rb +1 -1
- data/lib/fat_table/column.rb +31 -22
- data/lib/fat_table/db_handle.rb +61 -50
- data/lib/fat_table/evaluator.rb +20 -22
- data/lib/fat_table/formatters/aoa_formatter.rb +1 -2
- data/lib/fat_table/formatters/aoh_formatter.rb +1 -2
- data/lib/fat_table/formatters/formatter.rb +38 -33
- data/lib/fat_table/formatters/latex_formatter.rb +2 -2
- data/lib/fat_table/formatters/org_formatter.rb +5 -6
- data/lib/fat_table/formatters/term_formatter.rb +3 -5
- data/lib/fat_table/formatters/text_formatter.rb +3 -4
- data/lib/fat_table/patches.rb +29 -1
- data/lib/fat_table/table.rb +81 -77
- data/lib/fat_table/version.rb +1 -1
- metadata +80 -82
data/README.org
CHANGED
@@ -40,6 +40,19 @@ buffer as an org-table, ready for processing by other code blocks.
|
|
40
40
|
|
41
41
|
* Installation
|
42
42
|
|
43
|
+
** Prerequisites
|
44
|
+
The ~fat_table~ gem depends on several libraries being available for building,
|
45
|
+
mostly those concerned with accessing databases. On an ubuntu system, the
|
46
|
+
following packages should be installed before you install the ~fat_table~ gem:
|
47
|
+
|
48
|
+
- ruby-dev
|
49
|
+
- build-essential
|
50
|
+
- libsqlite3-dev
|
51
|
+
- libpq-dev
|
52
|
+
- libmysqlclient-dev
|
53
|
+
|
54
|
+
** Installing the gem
|
55
|
+
|
43
56
|
Add this line to your application's Gemfile:
|
44
57
|
|
45
58
|
#+BEGIN_SRC ruby
|
@@ -152,11 +165,11 @@ the main features of ~FatTable~. See the detailed explanations further on down.
|
|
152
165
|
|
153
166
|
** A Word About the Examples
|
154
167
|
|
155
|
-
When you install the fat_table gem, you have access to a program ~ft_console~
|
168
|
+
When you install the ~fat_table~ gem, you have access to a program ~ft_console~
|
156
169
|
which opens a ~pry~ session with ~fat_table~ loaded and the tables used in the
|
157
|
-
examples in this README defined as instance variables so you can experiment
|
158
|
-
them.
|
159
|
-
as ~@tab1~ in ~ft_console~, but otherwise the examples should work.
|
170
|
+
examples in this ~README~ defined as instance variables so you can experiment
|
171
|
+
with them. Because they are defined as instance variables, you have to write
|
172
|
+
~tab1~ as ~@tab1~ in ~ft_console~, but otherwise the examples should work.
|
160
173
|
|
161
174
|
The examples in this ~README~ file are executed as code blocks within the
|
162
175
|
~README.org~ file, so they typically end with a call to ~.to_aoa~. That causes
|
@@ -228,52 +241,52 @@ directives.
|
|
228
241
|
Each ~Column~ has a header, a type, and an array of items, all of the given type
|
229
242
|
or nil. There are only five permissible types for a ~Column~:
|
230
243
|
|
231
|
-
1. Boolean (for holding ruby ~TrueClass~ and ~FalseClass~ objects),
|
232
|
-
2. DateTime (for holding ruby ~DateTime~ or ~Date~ objects),
|
233
|
-
3. Numeric (for holding ruby ~Integer~, ~Rational~, or ~BigDecimal~ objects),
|
234
|
-
4. String (for ruby String objects), or
|
235
|
-
5. NilClass (for the undetermined column type).
|
244
|
+
1. *Boolean* (for holding ruby ~TrueClass~ and ~FalseClass~ objects),
|
245
|
+
2. *DateTime* (for holding ruby ~DateTime~ or ~Date~ objects),
|
246
|
+
3. *Numeric* (for holding ruby ~Integer~, ~Rational~, or ~BigDecimal~ objects),
|
247
|
+
4. *String* (for ruby ~String~ objects), or
|
248
|
+
5. *NilClass* (for the undetermined column type).
|
236
249
|
|
237
250
|
When a ~Table~ is constructed from an external source, all ~Columns~ start out
|
238
251
|
having a type of ~NilClass~, that is, their type is as yet undetermined. When a
|
239
252
|
string or object of one of the four determined types is added to a ~Column~, it
|
240
253
|
fixes the type of the column and all further items added to the ~Column~ must
|
241
|
-
either be nil (indicating no value) or be capable of being coerced to the
|
254
|
+
either be ~nil~ (indicating no value) or be capable of being coerced to the
|
242
255
|
column's type. Otherwise, ~FatTable~ raises an exception.
|
243
256
|
|
244
257
|
Items of input must be either one of the permissible ruby objects or strings. If
|
245
258
|
they are strings, ~FatTable~ attempts to parse them as one of the permissible
|
246
259
|
types as follows:
|
247
260
|
|
248
|
-
- Boolean :: the strings, 't'
|
249
|
-
interpreted as ~TrueClass~ and the strings, 'f'
|
250
|
-
regardless of case, are interpreted as ~FalseClass~, in
|
251
|
-
resulting in a Boolean column. Empty strings in a column
|
252
|
-
Boolean type are converted to nil
|
253
|
-
- DateTime :: strings that contain patterns of 'yyyy-mm-dd' or 'yyyy/mm/dd'
|
254
|
-
'mm-dd-yyy' or 'mm/dd/yyyy' or any of the foregoing with an added
|
255
|
-
'Thh:mm:ss' or 'Thh:mm' will be interpreted as a ~DateTime~ or a ~Date~
|
256
|
-
there are no sub-day time components present). The number of digits in
|
257
|
-
month and day can be one or two, but the year component must be four
|
261
|
+
- Boolean :: the strings, ~'t'~, ~'true'~, ~'yes'~, or ~'y'~, regardless of
|
262
|
+
case, are interpreted as ~TrueClass~ and the strings, ~'f'~, ~'false'~,
|
263
|
+
~'no'~, or ~'n'~, regardless of case, are interpreted as ~FalseClass~, in
|
264
|
+
either case resulting in a Boolean column. Empty strings in a column
|
265
|
+
already having a Boolean type are converted to ~nil~.
|
266
|
+
- DateTime :: strings that contain patterns of ~'yyyy-mm-dd'~ or ~'yyyy/mm/dd'~
|
267
|
+
or ~'mm-dd-yyy'~ or ~'mm/dd/yyyy'~ or any of the foregoing with an added
|
268
|
+
~'Thh:mm:ss'~ or ~'Thh:mm'~ will be interpreted as a ~DateTime~ or a ~Date~
|
269
|
+
(if there are no sub-day time components present). The number of digits in
|
270
|
+
the month and day can be one or two, but the year component must be four
|
258
271
|
digits. Any time components are valid if they can be properly interpreted
|
259
272
|
by ~DateTime.parse~. Org mode timestamps (any of the foregoing surrounded
|
260
|
-
by square '[]' or pointy '
|
261
|
-
input strings for DateTime columns. Empty strings in a column already
|
262
|
-
having the DateTime type are converted to nil
|
263
|
-
- Numeric :: all commas ','
|
264
|
-
currency symbol as set by ~FatTable.currency_symbol~ are removed from
|
265
|
-
string and if the remaining string can be interpreted as a ~Numeric~,
|
266
|
-
will be. It is interpreted as an ~Integer~ if there are no decimal
|
267
|
-
in the remaining string, as a ~Rational~ if the string has the form
|
268
|
-
'
|
269
|
-
is a decimal point in the remaining string. Empty strings in a column
|
273
|
+
by square '~[]~' or pointy '~<>~' brackets), active or inactive, are valid
|
274
|
+
input strings for ~DateTime~ columns. Empty strings in a column already
|
275
|
+
having the ~DateTime~ type are converted to ~nil~.
|
276
|
+
- Numeric :: all commas ~','~, underscores, ~'_'~, and ~'$'~ dollar signs (or
|
277
|
+
other currency symbol as set by ~FatTable.currency_symbol~ are removed from
|
278
|
+
the string and if the remaining string can be interpreted as a ~Numeric~,
|
279
|
+
it will be. It is interpreted as an ~Integer~ if there are no decimal
|
280
|
+
places in the remaining string, as a ~Rational~ if the string has the form
|
281
|
+
'~<number>:<number>~' or '~<number>/<number>~', or as a ~BigDecimal~ if
|
282
|
+
there is a decimal point in the remaining string. Empty strings in a column
|
270
283
|
already having the Numeric type are converted to nil.
|
271
284
|
- String :: if all else fails, ~FatTable~ applies ~#to_s~ to the input value
|
272
|
-
and, treats it as an item of type ~String~.
|
273
|
-
already having the String type are kept as empty strings.
|
285
|
+
and, treats it as an item of type ~String~. Empty strings in a column
|
286
|
+
already having the ~String~ type are kept as empty strings.
|
274
287
|
- NilClass :: until the input contains a non-blank string that can be parsed as
|
275
288
|
one of the other types, it has this type, meaning that the type is still
|
276
|
-
open. A column comprised completely of blank strings or nils will retain
|
289
|
+
open. A column comprised completely of blank strings or ~nils~ will retain
|
277
290
|
the ~NilClass~ type.
|
278
291
|
|
279
292
|
*** Headers
|
@@ -282,23 +295,23 @@ Headers for the columns are formed from the input. No two columns in a table can
|
|
282
295
|
have the same header. Headers in the input are converted to symbols by
|
283
296
|
|
284
297
|
- converting the header to a string with ~#to_s~,
|
285
|
-
- converting any run of blanks to an underscore
|
298
|
+
- converting any run of blanks to an underscore ~_~,
|
286
299
|
- removing any characters that are not letters, numbers, or underscores, and
|
287
300
|
- lowercasing all remaining letters
|
288
301
|
|
289
|
-
Thus, a header of 'Date' becomes ~:date~, a header of 'Id Number' becomes,
|
302
|
+
Thus, a header of ~'Date'~ becomes ~:date~, a header of ~'Id Number'~ becomes,
|
290
303
|
~:id_number~, etc. When referring to a column in code, you must use the symbol
|
291
304
|
form of the header.
|
292
305
|
|
293
306
|
If no sensible headers can be discerned from the input, headers of the form
|
294
|
-
|
307
|
+
~:col_1~, ~:col_2~, etc., are synthesized.
|
295
308
|
|
296
309
|
*** Groups
|
297
310
|
|
298
311
|
The rows of a ~FatTable~ table can be sub-divided into groups, either from
|
299
312
|
markers in the input or as a result of certain operations. There is only one
|
300
313
|
level of grouping, so ~FatTable~ has no concept of sub-groups. Groups can be
|
301
|
-
shown on output with rules or
|
314
|
+
shown on output with rules or "hlines" that underline the last row in each
|
302
315
|
group, and you can decorate the output with group footers that summarize the
|
303
316
|
columns in each group.
|
304
317
|
|
@@ -310,7 +323,7 @@ You can create an empty table with ~FatTable.new~, and then add rows with the
|
|
310
323
|
|
311
324
|
#+BEGIN_SRC ruby
|
312
325
|
tab = FatTable.new
|
313
|
-
tab << { a: 1, b: 2, c:
|
326
|
+
tab << { a: 1, b: 2, c: "<2017-01-21>', d: 'f', e: '' }
|
314
327
|
tab << { a: 3.14, b: 2.17, c: '[2016-01-21 Thu]', d: 'Y', e: nil }
|
315
328
|
tab.to_aoa
|
316
329
|
#+END_SRC
|
@@ -325,7 +338,7 @@ in org-mode time stamps.
|
|
325
338
|
|
326
339
|
Tables can also be read from ~.csv~ files or files containing ~org-mode~ tables.
|
327
340
|
In the case of org-mode files, ~FatTable~ skips through the file until it finds
|
328
|
-
a line that look like a table, that is it begins with any number of spaces
|
341
|
+
a line that look like a table, that is, it begins with any number of spaces
|
329
342
|
followed by ~|-~. Only the first table in an ~.org~ file is read.
|
330
343
|
|
331
344
|
For both ~.csv~ and ~.org~ files, the first row in the tables is taken as the
|
@@ -383,21 +396,22 @@ You can also initialize a table directly from ruby data structures. You can, for
|
|
383
396
|
example, build a table from an array of arrays:
|
384
397
|
|
385
398
|
#+BEGIN_SRC ruby
|
386
|
-
aoa =
|
387
|
-
[
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
399
|
+
aoa = [
|
400
|
+
['Ref', 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Bool'],
|
401
|
+
[1, '2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'ENTITY1', 'T'],
|
402
|
+
[2, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ENTITY1', 'T'],
|
403
|
+
[7, '2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'ENTITY3', 'F'],
|
404
|
+
[8, '2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'ENTITY3', 'T'],
|
405
|
+
[9, '2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'ENTITY3', 'T'],
|
406
|
+
[10, '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', 'T'],
|
407
|
+
[11, '2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'ENTITY3', 'F'],
|
408
|
+
[12, '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ENTITY3', 'T'],
|
409
|
+
[13, '2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'ENTITY3', 'T'],
|
410
|
+
[14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ENTITY3', 'F'],
|
411
|
+
[15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ENTITY3', 'T'],
|
412
|
+
[16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ENTITY3', 'T']
|
413
|
+
]
|
414
|
+
tab = FatTable.from_aoa(aoa)
|
401
415
|
#+END_SRC
|
402
416
|
|
403
417
|
Notice that the values can either be ruby objects, such as the Integer ~85_000~,
|
@@ -453,7 +467,7 @@ arrays is displayed as an org-mode table:
|
|
453
467
|
|
454
468
|
This example illustrates several things:
|
455
469
|
|
456
|
-
1. The named org-mode table,
|
470
|
+
1. The named org-mode table, ~trades1~, can be passed into a ruby code block
|
457
471
|
using the ~:var tab=trades1~ header argument to the code block; that makes
|
458
472
|
the variable ~tab~ available to the code block as an array of arrays, which
|
459
473
|
~FatTable~ then uses to initialize the table.
|
@@ -465,7 +479,7 @@ This example illustrates several things:
|
|
465
479
|
4. ~FatTable~ passes back to org-mode an array of arrays using the ~.to_aoa~
|
466
480
|
method. In an ~org-mode~ buffer, these are rendered as tables. We'll often
|
467
481
|
apply ~.to_aoa~ at the end of example blocks to render the results inside
|
468
|
-
this README.org file. As we'll see below, this method can also take a block
|
482
|
+
this ~README.org~ file. As we'll see below, this method can also take a block
|
469
483
|
to which formatting directives and footers can be attached.
|
470
484
|
|
471
485
|
*** From Arrays of Hashes
|
@@ -473,10 +487,12 @@ This example illustrates several things:
|
|
473
487
|
A second ruby data structure that can be used to initialize a ~FatTable~ table
|
474
488
|
is an array of ruby Hashes. Each hash represents a row of the table, and the
|
475
489
|
headers of the table are take from the keys of the hashes. Accordingly, all the
|
476
|
-
hashes should have the same keys.
|
477
|
-
|
478
|
-
|
479
|
-
a
|
490
|
+
hashes should have the same keys.
|
491
|
+
|
492
|
+
This same method can in fact take an array of any objects that can be converted
|
493
|
+
to a Hash with the ~#to_h~ method, so you can use an array of your own objects
|
494
|
+
to initialize a table, provided that you define a suitable ~#to_h~ method for
|
495
|
+
the objects' class.
|
480
496
|
|
481
497
|
#+BEGIN_SRC ruby
|
482
498
|
aoh = [
|
@@ -522,11 +538,11 @@ database parameters to be used for the queries.
|
|
522
538
|
#+END_SRC
|
523
539
|
|
524
540
|
Some of the parameters to the ~.set_db~ function have defaults. The driver
|
525
|
-
defaults to 'Pg' for postgresql and the socket defaults to
|
526
|
-
if the host is 'localhost', which it is by default. If the
|
527
|
-
'localhost'
|
528
|
-
'5432'
|
529
|
-
required.
|
541
|
+
defaults to ~'Pg'~ for postgresql and the socket defaults to
|
542
|
+
~/tmp/.s.PGSQL.5432~ if the host is 'localhost', which it is by default. If the
|
543
|
+
host is not ~'localhost'~, the dsn uses a port rather than a socket and defaults
|
544
|
+
to port ~'5432'~. While user and password default to nil, the database parameter
|
545
|
+
is required.
|
530
546
|
|
531
547
|
The ~.set_db~ function need only be called once, and the database handle it
|
532
548
|
creates will be used for all subsequent ~.from_sql~ calls until ~.set_db~ is
|
@@ -569,8 +585,8 @@ recognizes hlines in the input, so it takes no ~hlines:~ keyword parameter.
|
|
569
585
|
*** Rows
|
570
586
|
|
571
587
|
A ~FatTable~ table is an Enumerable, yielding each row of the table as a Hash
|
572
|
-
keyed on the header symbols.
|
573
|
-
Hashes as well.
|
588
|
+
keyed on the header symbols. The method ~Table#rows~ returns an Array of the
|
589
|
+
rows as Hashes as well.
|
574
590
|
|
575
591
|
You can also use indexing to access a row of the table by number. Using an
|
576
592
|
integer index returns a Hash of the given row. Thus, ~tab[20]~ returns the 21st
|
@@ -635,8 +651,8 @@ SQL.
|
|
635
651
|
|
636
652
|
For illustration purposes assume that the following tables are read into ruby
|
637
653
|
variables called '~tab1~' and '~tab2~. We have given the table groups, marked by
|
638
|
-
the hlines below, and some duplicate rows to illustrate the effect of
|
639
|
-
operations on groups and duplicates.
|
654
|
+
the hlines below, and included some duplicate rows to illustrate the effect of
|
655
|
+
certain operations on groups and duplicates.
|
640
656
|
|
641
657
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
642
658
|
#+BEGIN_SRC ruby
|
@@ -743,12 +759,13 @@ any group boundaries present in the input table.
|
|
743
759
|
|
744
760
|
**** Adding New Columns
|
745
761
|
|
746
|
-
More interesting is that ~select~ can take hash-like keyword arguments
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
symbol representing an existing column
|
751
|
-
expression for the value of
|
762
|
+
More interesting is that ~select~ can take hash-like keyword arguments after the
|
763
|
+
symbol arguments to create new columns in the output as functions of other
|
764
|
+
columns. For each hash-like parameter, the keyword given must be a symbol, which
|
765
|
+
becomes the header for the new column, and the value must be either: (1) a
|
766
|
+
symbol representing an existing column, which has the effect of renaming an
|
767
|
+
existing column, or (2) a string representing a ruby expression for the value of
|
768
|
+
a new column.
|
752
769
|
|
753
770
|
Within the string expression, the names of existing or already-specified columns
|
754
771
|
are available as local variables, as well as the instance variables '@row' and
|
@@ -759,8 +776,8 @@ access to local variables ~ref~, ~date~, ~code~, ~price~, ~g10~, ~qp10~,
|
|
759
776
|
their respective columns for each row in the input table and the instance
|
760
777
|
variables are set the number of the current row and group respectively.
|
761
778
|
|
762
|
-
For example, if we want to rename the
|
763
|
-
shares, we could do the following:
|
779
|
+
For example, if we want to rename the ~:date~ column and add a new column to
|
780
|
+
compute the cost of shares, we could do the following:
|
764
781
|
|
765
782
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
766
783
|
#+BEGIN_SRC ruby
|
@@ -840,18 +857,18 @@ second, chained call to ~select~:
|
|
840
857
|
**** Custom Instance Variables and Hooks
|
841
858
|
|
842
859
|
As the above examples demonstrate, the instance variables ~@row~ and ~@group~
|
843
|
-
are available when evaluating expressions that add new columns.
|
844
|
-
your own instance variables as well for keeping track of things that cross
|
845
|
-
boundaries, such as running sums.
|
860
|
+
are available when evaluating expressions that add new columns. You can also set
|
861
|
+
up your own instance variables as well for keeping track of things that cross
|
862
|
+
row boundaries, such as running sums.
|
846
863
|
|
847
864
|
To declare instance variables, you can use the ~ivars:~ hash parameter to
|
848
865
|
~select~. Each key of the hash becomes an instance variable and each value
|
849
866
|
becomes its initial value before any rows are evaluated.
|
850
867
|
|
851
|
-
In addition, you can provide ~before_hook:~ and ~after_hook:~ parameters
|
852
|
-
strings that are evaluated as ruby expressions before and after each
|
853
|
-
processed.
|
854
|
-
the ~before_hook:~ can be used in expressions for adding new columns by
|
868
|
+
In addition, you can provide ~before_hook:~ and ~after_hook:~ parameters to
|
869
|
+
~select~ as strings that are evaluated as ruby expressions before and after each
|
870
|
+
row is processed. You can use these to update instance variables. The values set
|
871
|
+
in the ~before_hook:~ can be used in expressions for adding new columns by
|
855
872
|
referencing them with the '@' prefix.
|
856
873
|
|
857
874
|
For example, suppose we wanted to not only add a cost column, but a column that
|
@@ -996,7 +1013,8 @@ which the grouping parameters are equal containing those columns and an
|
|
996
1013
|
aggregate column for each of the aggregating parameters.
|
997
1014
|
|
998
1015
|
For example, let's summarize the ~trades~ table by ~:code~ and ~:price~ again,
|
999
|
-
and determine total shares, average price, and other features of each
|
1016
|
+
and determine total shares, average price, and a few other features of each
|
1017
|
+
group:
|
1000
1018
|
|
1001
1019
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
1002
1020
|
#+BEGIN_SRC ruby
|
@@ -1030,38 +1048,39 @@ will raise an exception.
|
|
1030
1048
|
|
1031
1049
|
- ~first~ :: the first non-nil item in the column,
|
1032
1050
|
- ~last~ :: the last non-nil item in the column,
|
1033
|
-
- ~rng~ :: form a string of the form "#{first}..#{last}" to show the range of
|
1051
|
+
- ~rng~ :: form a string of the form ~"#{first}..#{last}"~ to show the range of
|
1034
1052
|
values in the column,
|
1035
|
-
- ~sum~ :: for Numeric and String columns, apply '+' to all the non-nil
|
1053
|
+
- ~sum~ :: for ~Numeric~ and ~String~ columns, apply '+' to all the non-nil
|
1054
|
+
values,
|
1036
1055
|
- ~count~ :: the number of non-nil values in the column,
|
1037
|
-
- ~min~ :: for Numeric
|
1038
|
-
value in the column,
|
1039
|
-
- ~max~ :: for Numeric
|
1040
|
-
value in the column,
|
1041
|
-
- ~avg~ :: for Numeric and DateTime columns, return the arithmetic mean of
|
1042
|
-
non-nil values in the column; with respect to
|
1043
|
-
converted to a numeric Julian date, the average is
|
1044
|
-
result converted back to a Date or DateTime object,
|
1045
|
-
- ~var~ :: for Numeric and DateTime columns, compute the sample variance of
|
1046
|
-
non-nil values in the column, dates are converted to
|
1047
|
-
|
1048
|
-
- ~pvar~ :: for Numeric and DateTime columns, compute the population
|
1049
|
-
the non-nil values in the column, dates are converted to
|
1050
|
-
|
1051
|
-
- ~dev~ :: for Numeric and DateTime columns, compute the sample standard
|
1056
|
+
- ~min~ :: for ~Numeric~, ~String~, and ~DateTime~ columns, return the smallest
|
1057
|
+
non-nil value in the column,
|
1058
|
+
- ~max~ :: for ~Numeric~, ~String~, and ~DateTime~ columns, return the largest
|
1059
|
+
non-nil value in the column,
|
1060
|
+
- ~avg~ :: for ~Numeric~ and ~DateTime~ columns, return the arithmetic mean of
|
1061
|
+
the non-nil values in the column; with respect to ~Date~ or ~DateTime~
|
1062
|
+
objects, each is converted to a numeric Julian date, the average is
|
1063
|
+
calculated, and the result converted back to a ~Date~ or ~DateTime~ object,
|
1064
|
+
- ~var~ :: for ~Numeric~ and ~DateTime~ columns, compute the sample variance of
|
1065
|
+
the non-nil values in the column, dates are converted to Julian date
|
1066
|
+
numbers as for the ~:avg~ aggregate,
|
1067
|
+
- ~pvar~ :: for ~Numeric~ and ~DateTime~ columns, compute the population
|
1068
|
+
variance of the non-nil values in the column, dates are converted to Julian
|
1069
|
+
date numbers as for the ~:avg~ aggregate,
|
1070
|
+
- ~dev~ :: for ~Numeric~ and ~DateTime~ columns, compute the sample standard
|
1052
1071
|
deviation of the non-nil values in the column, dates are converted to
|
1053
|
-
numbers as for the
|
1054
|
-
- ~pdev~ :: for Numeric and DateTime columns, compute the population
|
1055
|
-
deviation of the non-nil values in the column, dates are converted
|
1056
|
-
numbers as for the
|
1057
|
-
- ~all?~ :: for Boolean columns only, return true if all of the non-nil values
|
1072
|
+
Julian date numbers as for the ~:avg~ aggregate,
|
1073
|
+
- ~pdev~ :: for ~Numeric~ and ~DateTime~ columns, compute the population
|
1074
|
+
standard deviation of the non-nil values in the column, dates are converted
|
1075
|
+
to numbers as for the ~:avg~ aggregate,
|
1076
|
+
- ~all?~ :: for ~Boolean~ columns only, return true if all of the non-nil values
|
1058
1077
|
in the column are true,
|
1059
|
-
- ~any?~ :: for Boolean columns only, return true if any non-nil value in the
|
1078
|
+
- ~any?~ :: for ~Boolean~ columns only, return true if any non-nil value in the
|
1060
1079
|
column is true,
|
1061
|
-
- ~none?~ :: for Boolean columns only, return true if no non-nil value in the
|
1080
|
+
- ~none?~ :: for ~Boolean~ columns only, return true if no non-nil value in the
|
1062
1081
|
column is true,
|
1063
|
-
- ~one?~ :: for Boolean columns only, return true if exactly one non-nil value
|
1064
|
-
the column is true,
|
1082
|
+
- ~one?~ :: for ~Boolean~ columns only, return true if exactly one non-nil value
|
1083
|
+
in the column is true,
|
1065
1084
|
|
1066
1085
|
Perhaps surprisingly, the ~group_by~ method ignores any groups in its input and
|
1067
1086
|
results in no group boundaries in the output since each group formed by the
|
@@ -1073,36 +1092,37 @@ implicit ~order_by~ on the grouping columns is collapsed into a single row.
|
|
1073
1092
|
So far, all the operations have operated on a single table. ~FatTable~ provides
|
1074
1093
|
several ~join~ methods for combining two tables, each of which takes as
|
1075
1094
|
parameters (1) a second table and (2) except in the case of ~cross_join~, zero
|
1076
|
-
or more "join expressions".
|
1077
|
-
the method is called, ~T2~ is the table supplied as the first parameter
|
1078
|
-
and ~R1~ and ~R2~ are rows in their respective tables being considered
|
1079
|
-
inclusion in the joined output table.
|
1095
|
+
or more "join expressions". In the descriptions below, ~T1~ is the table on
|
1096
|
+
which the method is called, ~T2~ is the table supplied as the first parameter
|
1097
|
+
~other~, and ~R1~ and ~R2~ are rows in their respective tables being considered
|
1098
|
+
for inclusion in the joined output table.
|
1080
1099
|
|
1081
1100
|
- ~join(other, *jexps)~ :: Performs an "inner join" on the tables. For each row
|
1082
|
-
R1 of T1
|
1083
|
-
join condition with R1
|
1101
|
+
~R1~ of ~T1~, the joined table has a row for each row in ~T2~ that
|
1102
|
+
satisfies the join condition with ~R1~.
|
1084
1103
|
|
1085
1104
|
- ~left_join(other, *jexps)~ :: First, an inner join is performed. Then, for
|
1086
|
-
each row in T1 that does not satisfy the join condition with any row in
|
1087
|
-
a joined row is added with null values in columns of T2
|
1088
|
-
table always has at least one row for each row in T1
|
1105
|
+
each row in ~T1~ that does not satisfy the join condition with any row in
|
1106
|
+
~T2~, a joined row is added with null values in columns of ~T2~. Thus, the
|
1107
|
+
joined table always has at least one row for each row in ~T1~.
|
1089
1108
|
|
1090
1109
|
- ~right_join(other, *jexps)~ :: First, an inner join is performed. Then, for
|
1091
|
-
each row in T2 that does not satisfy the join condition with any row in
|
1092
|
-
a joined row is added with null values in columns of T1
|
1093
|
-
converse of a left join: the result table will always have a row for
|
1094
|
-
row in T2
|
1110
|
+
each row in ~T2~ that does not satisfy the join condition with any row in
|
1111
|
+
~T1~, a joined row is added with null values in columns of ~T1~. This is
|
1112
|
+
the converse of a left join: the result table will always have a row for
|
1113
|
+
each row in ~T2~.
|
1095
1114
|
|
1096
1115
|
- ~full_join(other, *jexps)~ :: First, an inner join is performed. Then, for
|
1097
|
-
each row in T1 that does not satisfy the join condition with any row in
|
1098
|
-
a joined row is added with null values in columns of T2
|
1099
|
-
of T2 that does not satisfy the join condition with any row in
|
1100
|
-
row with null values in the columns of T1 is added.
|
1116
|
+
each row in ~T1~ that does not satisfy the join condition with any row in
|
1117
|
+
~T2~, a joined row is added with null values in columns of ~T2~. Also, for
|
1118
|
+
each row of ~T2~ that does not satisfy the join condition with any row in
|
1119
|
+
~T1~, a joined row with null values in the columns of ~T1~ is added.
|
1101
1120
|
|
1102
|
-
- ~cross_join(other)~ :: For every possible combination of rows from T1 and
|
1103
|
-
(i.e., a Cartesian product), the joined table will contain a row
|
1104
|
-
of all columns in T1 followed by all columns in T2
|
1105
|
-
and M rows respectively, the joined table will have N *
|
1121
|
+
- ~cross_join(other)~ :: For every possible combination of rows from ~T1~ and
|
1122
|
+
~T2~ (i.e., a Cartesian product), the joined table will contain a row
|
1123
|
+
consisting of all columns in ~T1~ followed by all columns in ~T2~. If the
|
1124
|
+
tables have ~N~ and ~M~ rows respectively, the joined table will have ~N *
|
1125
|
+
M~ rows.
|
1106
1126
|
|
1107
1127
|
**** Join Expressions
|
1108
1128
|
|
@@ -1116,8 +1136,8 @@ that the values of both tables are equal for all columns named by the symbols. A
|
|
1116
1136
|
column that appears in both tables can be given without modification and will be
|
1117
1137
|
assumed to require equality on that column. If an unmodified symbol is not a
|
1118
1138
|
name that appears in both tables, an exception will be raised. Column names that
|
1119
|
-
are unique to the first table must have a
|
1120
|
-
column names that are unique to the other table must have a
|
1139
|
+
are unique to the first table must have a ~_a~ appended to the column name and
|
1140
|
+
column names that are unique to the other table must have a ~_b~ appended to the
|
1121
1141
|
column name. These disambiguated column names must come in pairs, one for the
|
1122
1142
|
first table and one for the second, and they will imply a join condition that
|
1123
1143
|
the columns must be equal on those columns. Several such symbol expressions will
|
@@ -1126,7 +1146,7 @@ be met.
|
|
1126
1146
|
|
1127
1147
|
Finally, a join expression can be a string that contains an arbitrary ruby
|
1128
1148
|
expression that will be evaluated for truthiness. Within the string, /all/
|
1129
|
-
column names must be disambiguated with the
|
1149
|
+
column names must be disambiguated with the ~_a~ or ~_b~ modifiers whether they
|
1130
1150
|
are common to both tables or not. As with ~select~ and ~where~ methods, the
|
1131
1151
|
names of the columns in both tables (albeit disambiguated) are available as
|
1132
1152
|
local variables within the expression, but the instance variables ~@row~ and
|
@@ -1134,9 +1154,9 @@ local variables within the expression, but the instance variables ~@row~ and
|
|
1134
1154
|
|
1135
1155
|
**** Join Examples
|
1136
1156
|
|
1137
|
-
The following examples are taken from
|
1138
|
-
|
1139
|
-
|
1157
|
+
The following examples are taken from the [[https://www.tutorialspoint.com/postgresql/postgresql_using_joins.htm][Postgresql tutorial]], with some slight
|
1158
|
+
modifications. The examples will use the following two tables, which are also
|
1159
|
+
available in ~ft_console~ as ~@tab_a~ and ~@tab_b~:
|
1140
1160
|
|
1141
1161
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
1142
1162
|
#+BEGIN_SRC ruby
|
@@ -1326,10 +1346,10 @@ Finally, a cross join outputs every row of ~tab_a~ augmented with every row of
|
|
1326
1346
|
|
1327
1347
|
*** Set Operations
|
1328
1348
|
|
1329
|
-
~FatTable~ can perform several set operations on tables.
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1349
|
+
~FatTable~ can perform several set operations on tables. In order for two tables
|
1350
|
+
to be used this way, they must have the same number of columns with the same
|
1351
|
+
types or an exception will be raised. We'll call two tables that qualify for
|
1352
|
+
combining with set operations "set-compatible."
|
1333
1353
|
|
1334
1354
|
We'll use the following two set-compatible tables in the examples. They each
|
1335
1355
|
have some duplicates and some group boundaries so you can see the effect of the
|
@@ -1400,7 +1420,7 @@ set operations on duplicates and groups.
|
|
1400
1420
|
Two tables that are set-compatible can be combined with the ~union~ or
|
1401
1421
|
~union_all~ methods so that the rows of both tables appear in the output. In the
|
1402
1422
|
output table, the headers of the receiver table are used. You can use ~select~
|
1403
|
-
to change or re-order the headers if you prefer.
|
1423
|
+
to change or re-order the headers if you prefer. The ~union~ method eliminates
|
1404
1424
|
duplicate rows in the result table, the ~union_all~ method does not.
|
1405
1425
|
|
1406
1426
|
Any group boundaries in the input tables are destroyed by ~union~ but are
|
@@ -1511,7 +1531,7 @@ eliminating any duplicate rows in the result.
|
|
1511
1531
|
#+END_EXAMPLE
|
1512
1532
|
|
1513
1533
|
With ~intersect_all~, all the rows of the first table, including duplicates, are
|
1514
|
-
included in the result if they also occur in the second table.
|
1534
|
+
included in the result if they also occur in the second table. However,
|
1515
1535
|
duplicates in the second table do not appear.
|
1516
1536
|
|
1517
1537
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
@@ -1710,21 +1730,20 @@ receiver table by removing its groups.
|
|
1710
1730
|
** Formatting Tables
|
1711
1731
|
|
1712
1732
|
Besides creating and operating on tables, you may want to display the resulting
|
1713
|
-
table.
|
1714
|
-
most common across many output media.
|
1733
|
+
table. ~FatTable~ seeks to provide a set of formatting directives that are the
|
1734
|
+
most common across many output media. It provides directives for alignment, for
|
1715
1735
|
color, for adding currency symbols and grouping commas to numbers, for padding
|
1716
1736
|
numbers, and for formatting dates and booleans.
|
1717
1737
|
|
1718
1738
|
In addition, you can add any number of footers to a table, which appear at the
|
1719
1739
|
end of the table, and any number of group footers, which appear after each group
|
1720
|
-
in the table.
|
1740
|
+
in the table. These can be formatted independently of the table body.
|
1721
1741
|
|
1722
1742
|
If the target output medium does not support a formatting directive or the
|
1723
|
-
directive
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
alignment are simply irrelevant.
|
1743
|
+
directive does not make sense, it is simply ignored. For example, you can output
|
1744
|
+
an ~org-mode~ table as a String, and since ~org-mode~ does not support colors,
|
1745
|
+
any color directives are ignored. Some of the output targets are not strings,
|
1746
|
+
but ruby data structures, and for them, things such as alignment are irrelevant.
|
1728
1747
|
|
1729
1748
|
*** Available Formatters
|
1730
1749
|
|
@@ -1743,13 +1762,13 @@ alignment are simply irrelevant.
|
|
1743
1762
|
|
1744
1763
|
These are all implemented by classes that inherit from ~FatTable::Formatter~
|
1745
1764
|
class by defining about a dozen methods that get called at various places during
|
1746
|
-
the construction of the output table.
|
1765
|
+
the construction of the output table. The idea is that more classes can be
|
1747
1766
|
defined by adding additional classes.
|
1748
1767
|
|
1749
1768
|
*** Table Locations
|
1750
1769
|
|
1751
1770
|
In the formatting methods, the table is divided into several "locations" for
|
1752
|
-
which separate formatting directives may be given.
|
1771
|
+
which separate formatting directives may be given. These locations are
|
1753
1772
|
identified with the following symbols:
|
1754
1773
|
|
1755
1774
|
- :header :: the first row of the output table containing the headers,
|
@@ -1794,8 +1813,8 @@ to a string in forming the output.
|
|
1794
1813
|
- _ ~_ :: underline the element, or turn off underline
|
1795
1814
|
- * ~* :: cause the element to blink, or turn off blink
|
1796
1815
|
|
1797
|
-
For example, the directive 'tCc[red.yellow]' would title-case the element,
|
1798
|
-
center it, and color it red on a yellow background.
|
1816
|
+
For example, the directive ~'tCc[red.yellow]'~ would title-case the element,
|
1817
|
+
center it, and color it red on a yellow background. The directives that are
|
1799
1818
|
boolean have negating forms so that, for example, if bold is turned on for all
|
1800
1819
|
columns of a given type, it can be countermanded in formatting directives for
|
1801
1820
|
particular columns.
|
@@ -1811,65 +1830,63 @@ addition to the following:
|
|
1811
1830
|
the left with zeroes as needed, and round the number to the n
|
1812
1831
|
decimal places and include n digits after the decimal point,
|
1813
1832
|
padding on the right with zeroes as needed,
|
1814
|
-
- H :: convert the number (assumed to be in units of seconds) to
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
formatting instruction.
|
1833
|
+
- H :: convert the number (assumed to be in units of seconds) to ~HH:MM:SS.ss~
|
1834
|
+
form. So a column that is the result of subtracting two :datetime forms
|
1835
|
+
will result in a :numeric expressed as seconds and can be displayed in
|
1836
|
+
hours, minutes, and seconds with this formatting instruction.
|
1819
1837
|
|
1820
|
-
For example, the directive 'R5.0c[blue]' would right-align the numeric
|
1821
|
-
pad it on the left with zeros, and color it blue.
|
1838
|
+
For example, the directive ~'R5.0c[blue]'~ would right-align the numeric
|
1839
|
+
element, pad it on the left with zeros, and color it blue.
|
1822
1840
|
|
1823
1841
|
**** DateTime
|
1824
1842
|
|
1825
|
-
For a
|
1826
|
-
to the following:
|
1843
|
+
For a ~DateTime~, all the instructions valid for string are available, in
|
1844
|
+
addition to the following:
|
1827
1845
|
|
1828
|
-
- d[fmt] :: apply the format to a
|
1829
|
-
no or zero hour, minute, and second components, where fmt
|
1830
|
-
string for Date#strftime
|
1831
|
-
ISO 8601 string, YYYY-MM-DD.
|
1832
|
-
- D[fmt] :: apply the format to a datetime that has at least a non-zero
|
1833
|
-
|
1834
|
-
|
1835
|
-
8601 string, YYYY-MM-DD.
|
1846
|
+
- d[fmt] :: apply the format to a ~Date~ or a ~DateTime~ that is a whole day,
|
1847
|
+
that is that has no or zero hour, minute, and second components, where fmt
|
1848
|
+
is a valid format string for ~Date#strftime~, otherwise, the datetime will
|
1849
|
+
be formatted as an ISO 8601 string, YYYY-MM-DD.
|
1850
|
+
- D[fmt] :: apply the format to a datetime that has at least a non-zero hour
|
1851
|
+
component where fmt is a valid format string for Date#strftime, otherwise,
|
1852
|
+
the datetime will be formatted as an ISO 8601 string, YYYY-MM-DD.
|
1836
1853
|
|
1837
|
-
For example, 'c[pink]d[%b %-d, %Y]C'
|
1838
|
-
1957', center it, and color it pink.
|
1854
|
+
For example, ~'c[pink]d[%b %-d, %Y]C'~, would format a date element like 'Sep
|
1855
|
+
22, 1957', center it, and color it pink.
|
1839
1856
|
|
1840
1857
|
**** Boolean
|
1841
1858
|
|
1842
1859
|
For a boolean cell, all the instructions valid for string are available, in
|
1843
|
-
|
1860
|
+
addition to the following:
|
1844
1861
|
|
1845
|
-
- Y :: print true as 'Y' and false as 'N',
|
1846
|
-
- T :: print true as 'T' and false as 'F',
|
1847
|
-
- X :: print true as 'X' and false as '',
|
1848
|
-
- b[xxx,yyy] :: print true as the string given as xxx and false as the
|
1849
|
-
|
1850
|
-
- c[tcolor,fcolor] :: color a true element with tcolor and a false
|
1851
|
-
|
1852
|
-
|
1862
|
+
- Y :: print true as '~Y~' and false as '~N~',
|
1863
|
+
- T :: print true as '~T~' and false as '~F~',
|
1864
|
+
- X :: print true as '~X~' and false as an empty string '',
|
1865
|
+
- b[xxx,yyy] :: print true as the string given as ~xxx~ and false as the string
|
1866
|
+
given as ~yyy~,
|
1867
|
+
- c[tcolor,fcolor] :: color a true element with ~tcolor~ and a false element
|
1868
|
+
with ~fcolor~. Each of the colors may be specified in the same manner as
|
1869
|
+
colors for strings described above.
|
1853
1870
|
|
1854
|
-
For example, the directive 'b[Yeppers,Nope]c[green.pink,red.pink]' would
|
1855
|
-
a true boolean as 'Yeppers' colored green on pink and render a false
|
1856
|
-
'Nope' colored red on pink. See [[https://www.youtube.com/watch?v=oLdFFD8II8U][Yeppers]].
|
1871
|
+
For example, the directive '~b[Yeppers,Nope]c[green.pink,red.pink]~' would
|
1872
|
+
render a true boolean as '~Yeppers~' colored green on pink and render a false
|
1873
|
+
boolean as '~Nope~' colored red on pink. See [[https://www.youtube.com/watch?v=oLdFFD8II8U][Yeppers]] for additional information.
|
1857
1874
|
|
1858
1875
|
**** NilClass
|
1859
1876
|
|
1860
|
-
By default, nil elements are rendered as blank cells, but you can make them
|
1877
|
+
By default, ~nil~ elements are rendered as blank cells, but you can make them
|
1861
1878
|
visible with the following, and in that case, all the formatting instructions
|
1862
1879
|
valid for strings are also available:
|
1863
1880
|
|
1864
|
-
- n[niltext] :: render a nil item with the given
|
1881
|
+
- n[niltext] :: render a ~nil~ item with the given niltext.
|
1865
1882
|
|
1866
|
-
For example, you might want to use 'n[-]Cc[purple]' to make nils visible as a
|
1867
|
-
centered hyphen.
|
1883
|
+
For example, you might want to use ~'n[-]Cc[purple]'~ to make nils visible as a
|
1884
|
+
centered purple hyphen.
|
1868
1885
|
|
1869
1886
|
*** Footers Methods
|
1870
1887
|
|
1871
|
-
You can call methods on
|
1872
|
-
Their signatures are:
|
1888
|
+
You can call the ~footer~ and ~gfooter~ methods on ~Formatter~ objects to add
|
1889
|
+
footers and group footers. Their signatures are:
|
1873
1890
|
|
1874
1891
|
- ~footer(label, *sum_cols, **agg_cols)~ :: where ~label~ is a label to be
|
1875
1892
|
placed in the first cell of the footer (unless that column is named as one
|
@@ -1877,8 +1894,8 @@ Their signatures are:
|
|
1877
1894
|
~*sum_cols~ are zero or more symbols for columns to be summed, and
|
1878
1895
|
~**agg_cols~ is zero or more hash-like parameters with a column symbol as a
|
1879
1896
|
key and a symbol for an aggregate method as the value. This causes a
|
1880
|
-
table-wide header to be added at the bottom of the table applying the
|
1881
|
-
aggregate to the ~sum_cols~ and the named aggregate method to the
|
1897
|
+
table-wide header to be added at the bottom of the table applying the
|
1898
|
+
~:sum~ aggregate to the ~sum_cols~ and the named aggregate method to the
|
1882
1899
|
~agg_cols~. A table can have any number of footers attached, and they will
|
1883
1900
|
appear at the bottom of the output table in the order they are given.
|
1884
1901
|
|
@@ -1915,10 +1932,10 @@ and ~format~.
|
|
1915
1932
|
**** Instantiating a Formatter
|
1916
1933
|
|
1917
1934
|
There are several ways to invoke the formatting methods on a table. First, you
|
1918
|
-
can instantiate a ~XXXFormatter~ object
|
1919
|
-
subclass for each target output medium, for example,
|
1920
|
-
a ruby array of arrays. You can then call the
|
1921
|
-
~XXXFormatter~.
|
1935
|
+
can instantiate a ~XXXFormatter~ object and feed it a table as a parameter.
|
1936
|
+
There is a Formatter subclass for each target output medium, for example,
|
1937
|
+
~AoaFormatter~ will produce a ruby array of arrays. You can then call the
|
1938
|
+
~output~ method on the ~XXXFormatter~.
|
1922
1939
|
|
1923
1940
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
1924
1941
|
#+BEGIN_SRC ruby
|
@@ -2072,12 +2089,12 @@ Other than that first parameter, the two methods take the same types of
|
|
2072
2089
|
parameters. The remaining parameters are hash-like parameters that use either a
|
2073
2090
|
column name or a type as the key and a string with the formatting directives to
|
2074
2091
|
apply as the value. The following example says to set the formatting for all
|
2075
|
-
locations in the table and to
|
2076
|
-
numbers (the '0.0' part), that are right-aligned (the 'R'
|
2077
|
-
grouping commas inserted (the ',' part). But the ~:id~ column is
|
2078
|
-
the second parameter overrides the formatting for numerics in
|
2079
|
-
for the ~:id~ column to be padded to three digits with zeros
|
2080
|
-
'3.0' part) and to be centered (the 'C' part).
|
2092
|
+
locations in the table and to format all numeric fields as strings that are
|
2093
|
+
rounded to whole numbers (the '0.0' part), that are right-aligned (the 'R'
|
2094
|
+
part), and have grouping commas inserted (the ',' part). But the ~:id~ column is
|
2095
|
+
numeric, and the second parameter overrides the formatting for numerics in
|
2096
|
+
general and calls for the ~:id~ column to be padded to three digits with zeros
|
2097
|
+
on the left (the '3.0' part) and to be centered (the 'C' part).
|
2081
2098
|
|
2082
2099
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
2083
2100
|
#+BEGIN_SRC ruby
|
@@ -2100,14 +2117,14 @@ for the ~:id~ column to be padded to three digits with zeros on the left (the
|
|
2100
2117
|
#+END_EXAMPLE
|
2101
2118
|
|
2102
2119
|
The ~numeric:~ directive affected the ~:age~ and ~:salary~ columns and the ~id:~
|
2103
|
-
directive affected only the ~:id~ column.
|
2120
|
+
directive affected only the ~:id~ column. All the other cells in the table had
|
2104
2121
|
the default formatting applied.
|
2105
2122
|
|
2106
2123
|
**** Location priority
|
2107
2124
|
|
2108
|
-
Formatting for any given cell depends on its location in the table.
|
2125
|
+
Formatting for any given cell depends on its location in the table. The
|
2109
2126
|
~format_for~ method takes a location to which its formatting directive are
|
2110
|
-
restricted as the first argument.
|
2127
|
+
restricted as the first argument. It can be one of the following:
|
2111
2128
|
|
2112
2129
|
- ~:header~ :: directive apply only to the header row, that is the first row, of
|
2113
2130
|
the output table,
|
@@ -2122,11 +2139,11 @@ restricted as the first argument. It can be one of the following:
|
|
2122
2139
|
row is the first row in the table or in a group and separate directives for
|
2123
2140
|
those have been given, in which case those directives apply,
|
2124
2141
|
|
2125
|
-
- ~:gfirst~ :: directives apply to the first row in each group in the
|
2126
|
-
table, unless the row is also the first row in the table as a whole, in
|
2142
|
+
- ~:gfirst~ :: directives apply to the first row in each group in the body of
|
2143
|
+
the table, unless the row is also the first row in the table as a whole, in
|
2127
2144
|
which case the ~:bfirst~ directives apply,
|
2128
2145
|
|
2129
|
-
- ~:bfirst~ :: directives apply to the first row in the table.
|
2146
|
+
- ~:bfirst~ :: directives apply to the first row in the body of the table.
|
2130
2147
|
|
2131
2148
|
If you give directives for ~:body~, they are copied to ~:bfirst~ and ~:gfirst~
|
2132
2149
|
as well and can be overridden by directives for those locations.
|
@@ -2171,7 +2188,8 @@ require 'fat_table'
|
|
2171
2188
|
|
2172
2189
|
The ~string: 'R'~ directive causes all the cells to be right-aligned except
|
2173
2190
|
~:id~ which specifies centering for the ~:id~ column only. The ~n[N/A]~
|
2174
|
-
directive for
|
2191
|
+
directive for specifies how nil are displayed in the numeric column, ~:salary~,
|
2192
|
+
but not for other nils, such as in the last row of the ~:join_date~ column.
|
2175
2193
|
|
2176
2194
|
* Development
|
2177
2195
|
|