fat_table 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-with-dbs.yml +34 -53
- data/.gitignore +1 -0
- data/CHANGELOG.md +88 -72
- data/CHANGELOG.org +6 -0
- data/Gemfile +3 -2
- data/README.md +171 -228
- data/README.org +127 -180
- data/lib/core_ext/array.rb +1 -1
- data/lib/core_ext/numeric_string.rb +0 -2
- data/lib/fat_table/evaluator.rb +1 -2
- data/lib/fat_table/formatters/formatter.rb +1 -2
- data/lib/fat_table/table.rb +5 -3
- data/lib/fat_table/version.rb +1 -1
- metadata +2 -2
data/README.org
CHANGED
|
@@ -5,10 +5,16 @@
|
|
|
5
5
|
#+STARTUP: inlineimages
|
|
6
6
|
#+PROPERTY: header-args:ruby :results value :colnames no :hlines yes :exports both :dir "./"
|
|
7
7
|
#+PROPERTY: header-args:ruby :wrap example :session fat_table_session
|
|
8
|
+
#+PROPERTY: header-args:ruby+ :ruby "bundle exec irb"
|
|
8
9
|
#+PROPERTY: header-args:ruby+ :prologue "$:.unshift('./lib') unless $:.first == './lib'; require 'fat_table'" :eval yes
|
|
9
10
|
#+PROPERTY: header-args:sh :exports code :eval no
|
|
10
11
|
#+PROPERTY: header-args:bash :exports code :eval no
|
|
11
12
|
|
|
13
|
+
# gem_docs:version begin
|
|
14
|
+
Version: 1.1.0
|
|
15
|
+
# gem_docs:version end
|
|
16
|
+
|
|
17
|
+
|
|
12
18
|
|
|
13
19
|
#+BEGIN_EXPORT markdown
|
|
14
20
|
[](
|
|
@@ -23,7 +29,7 @@ https://github.com/ddoherty03/fat_table/actions/workflows/ruby-with-dbs.yml
|
|
|
23
29
|
|
|
24
30
|
#+RESULTS:
|
|
25
31
|
#+begin_example
|
|
26
|
-
Current version is: 1.
|
|
32
|
+
Current version is: 1.1.0
|
|
27
33
|
#+end_example
|
|
28
34
|
|
|
29
35
|
* Introduction
|
|
@@ -134,7 +140,7 @@ org-mode buffer as an org-table, ready for processing by other code blocks.
|
|
|
134
140
|
- [[#boolean][Boolean]]
|
|
135
141
|
- [[#nilclass][NilClass]]
|
|
136
142
|
- [[#the-format-and-format_for-methods][The ~format~ and ~format_for~ methods]]
|
|
137
|
-
- [[#table
|
|
143
|
+
- [[#locations-within-a-table][Locations within a Table]]
|
|
138
144
|
- [[#location-priority][Location priority]]
|
|
139
145
|
- [[#type-and-column-priority][Type and Column priority]]
|
|
140
146
|
- [[#footers][Footers]]
|
|
@@ -173,7 +179,7 @@ Or, something like this in your gemspec file:
|
|
|
173
179
|
|
|
174
180
|
#+RESULTS:
|
|
175
181
|
#+begin_example
|
|
176
|
-
|
|
182
|
+
#<ArgumentError: wrong number of arguments (given 0, expected 1+)>
|
|
177
183
|
#+end_example
|
|
178
184
|
|
|
179
185
|
And then execute:
|
|
@@ -311,7 +317,6 @@ We can format the table constructed above.
|
|
|
311
317
|
+============+======+=============+=============+==========+=========+====+
|
|
312
318
|
#+end_example
|
|
313
319
|
|
|
314
|
-
|
|
315
320
|
For the text format above, we were wasting our breath specifying bold styling
|
|
316
321
|
since there is no way to make that happen in plain ASCII text. But with
|
|
317
322
|
LaTeX, bold is doable. The output of the following code block is being
|
|
@@ -453,7 +458,6 @@ no value) or be capable of being coerced to the column's type. Otherwise,
|
|
|
453
458
|
~FatTable~ raises an ~IncompatibleTypeError~ exception.
|
|
454
459
|
|
|
455
460
|
*** Type Keywords Arguments
|
|
456
|
-
|
|
457
461
|
All of the table constructors allow you to set the type for a column in
|
|
458
462
|
advance by adding keyword arguments to the end of the contructor arguments
|
|
459
463
|
where the keyword is a header symbol and the value is a string designating one
|
|
@@ -587,15 +591,6 @@ in org-mode time stamps.
|
|
|
587
591
|
+========+========+============+===+===+
|
|
588
592
|
#+end_example
|
|
589
593
|
|
|
590
|
-
#+begin_EXAMPLE
|
|
591
|
-
+======+======+============+===+===+
|
|
592
|
-
| A | B | C | D | E |
|
|
593
|
-
+------+------+------------+---+---+
|
|
594
|
-
| 1 | 2 | 2017-01-21 | F | |
|
|
595
|
-
| 3.14 | 2.17 | 2016-01-21 | T | |
|
|
596
|
-
+======+======+============+===+===+
|
|
597
|
-
#+end_EXAMPLE
|
|
598
|
-
|
|
599
594
|
You can continue to add rows to the table:
|
|
600
595
|
#+BEGIN_SRC ruby :results silent
|
|
601
596
|
tab << { 'F' => '335:113', a: Rational(3, 5) }
|
|
@@ -620,19 +615,7 @@ for which no key was give are assigned ~nil~ as well:
|
|
|
620
615
|
+========+========+============+===+===+=========+
|
|
621
616
|
#+end_example
|
|
622
617
|
|
|
623
|
-
#+begin_EXAMPLE
|
|
624
|
-
+======+======+============+===+===+=========+
|
|
625
|
-
| A | B | C | D | E | F |
|
|
626
|
-
+------+------+------------+---+---+---------+
|
|
627
|
-
| 1 | 2 | 2017-01-21 | F | | |
|
|
628
|
-
| 3.14 | 2.17 | 2016-01-21 | T | | |
|
|
629
|
-
+------+------+------------+---+---+---------+
|
|
630
|
-
| 3/5 | | | | | 335/113 |
|
|
631
|
-
+======+======+============+===+===+=========+
|
|
632
|
-
#+end_EXAMPLE
|
|
633
|
-
|
|
634
618
|
**** With Headers
|
|
635
|
-
|
|
636
619
|
Alternatively, you can specify the headers at the outset, in which case,
|
|
637
620
|
headers in added rows that do not match any of the initial headers cause new
|
|
638
621
|
columns to be created:
|
|
@@ -648,10 +631,6 @@ columns to be created:
|
|
|
648
631
|
[:a, :b, :c, :d]
|
|
649
632
|
#+end_example
|
|
650
633
|
|
|
651
|
-
#+begin_EXAMPLE
|
|
652
|
-
[:a, :b, :c, :d]
|
|
653
|
-
#+end_EXAMPLE
|
|
654
|
-
|
|
655
634
|
#+begin_src ruby
|
|
656
635
|
tab << { a: 1, b: 2, c: "<2017-01-21>", d: 'f', e: '' }
|
|
657
636
|
tab << { a: 3.14, b: 2.17, c: '[2016-01-21 Thu]', d: 'Y', e: nil }
|
|
@@ -668,18 +647,6 @@ columns to be created:
|
|
|
668
647
|
+========+========+============+===+===+
|
|
669
648
|
#+end_example
|
|
670
649
|
|
|
671
|
-
#+begin_EXAMPLE
|
|
672
|
-
+======+======+============+===+===+
|
|
673
|
-
| A | B | C | D | E |
|
|
674
|
-
+------+------+------------+---+---+
|
|
675
|
-
| 1 | 2 | 2017-01-21 | F | |
|
|
676
|
-
| 3.14 | 2.17 | 2016-01-21 | T | |
|
|
677
|
-
+------+------+------------+---+---+
|
|
678
|
-
| 1 | 2 | 2017-01-21 | F | |
|
|
679
|
-
| 3.14 | 2.17 | 2016-01-21 | T | |
|
|
680
|
-
+======+======+============+===+===+
|
|
681
|
-
#+end_EXAMPLE
|
|
682
|
-
|
|
683
650
|
**** Forcing String Type
|
|
684
651
|
|
|
685
652
|
Occasionally, ~FatTable~'s automatic type detection can get in the way and you
|
|
@@ -712,18 +679,6 @@ using a keyword parameter.
|
|
|
712
679
|
+========+========+============+===+=============+===+
|
|
713
680
|
#+end_example
|
|
714
681
|
|
|
715
|
-
#+begin_EXAMPLE
|
|
716
|
-
+===+===+============+===+=============+===+
|
|
717
|
-
| A | B | C | D | Zip | E |
|
|
718
|
-
+---+---+------------+---+-------------+---+
|
|
719
|
-
| 1 | 2 | 2017-01-21 | F | 18552 | |
|
|
720
|
-
| 3 | 2 | 2016-01-21 | T | | |
|
|
721
|
-
| | | | | 01879--7884 | |
|
|
722
|
-
| | | | | 90210 | |
|
|
723
|
-
| | | | | | |
|
|
724
|
-
+===+===+============+===+=============+===+
|
|
725
|
-
#+end_EXAMPLE
|
|
726
|
-
|
|
727
682
|
In addition, at any time after creating a table, you can force the String type
|
|
728
683
|
on any number of columns with the ~force_string!~ method. When you do so, all
|
|
729
684
|
exisiting items in the column are converted to strings with the #to_s method.
|
|
@@ -752,18 +707,6 @@ exisiting items in the column are converted to strings with the #to_s method.
|
|
|
752
707
|
+========+========+============+===+=======+===+
|
|
753
708
|
#+end_example
|
|
754
709
|
|
|
755
|
-
#+begin_EXAMPLE
|
|
756
|
-
+======+======+============+===+=======+===+
|
|
757
|
-
| A | B | C | D | Zip | E |
|
|
758
|
-
+------+------+------------+---+-------+---+
|
|
759
|
-
| 1 | 2 | 2017-01-21 | F | 18552 | |
|
|
760
|
-
| 3.14 | 2.17 | 2016-01-21 | T | | |
|
|
761
|
-
| | | | | 01879 | |
|
|
762
|
-
| | | | | 66210 | |
|
|
763
|
-
| | | | | 90210 | |
|
|
764
|
-
+======+======+============+===+=======+===+
|
|
765
|
-
#+end_EXAMPLE
|
|
766
|
-
|
|
767
710
|
*** From CSV or Org Mode files or strings
|
|
768
711
|
Tables can also be read from ~.csv~ files or files containing ~org-mode~
|
|
769
712
|
tables.
|
|
@@ -980,7 +923,7 @@ tab = FatTable.from_aoh(aoh).to_aoa
|
|
|
980
923
|
| T002 | 2016-11-01 | P | 7.7500 | 200 |
|
|
981
924
|
| T003 | 2016-11-01 | P | 7.5000 | 800 |
|
|
982
925
|
| T004 | 2016-11-01 | S | 7.5500 | 6811 |
|
|
983
|
-
| T005 |
|
|
926
|
+
| T005 | 2026-11-23 | S | 7.5000 | 4000 |
|
|
984
927
|
| T006 | 2016-11-01 | S | 7.6000 | 1000 |
|
|
985
928
|
| T007 | 2016-11-01 | S | 7.6500 | 200 |
|
|
986
929
|
| T008 | 2016-11-01 | P | 7.6500 | 2771 |
|
|
@@ -1168,10 +1111,7 @@ requires it to synthesize the type from these Ruby classes.
|
|
|
1168
1111
|
|
|
1169
1112
|
#+RESULTS:
|
|
1170
1113
|
#+begin_example
|
|
1171
|
-
=> false
|
|
1172
1114
|
Column :shares says its type is 'Numeric' and that is a BigDecimal
|
|
1173
|
-
=> nil
|
|
1174
|
-
:org_babel_ruby_eoe
|
|
1175
1115
|
#+end_example
|
|
1176
1116
|
|
|
1177
1117
|
** Operations on Tables
|
|
@@ -1180,12 +1120,12 @@ them. The operations provided by ~FatTable~ are the subject of this section.
|
|
|
1180
1120
|
Before getting into the operations, though, there are a couple of issues that
|
|
1181
1121
|
cut across all or many of the operations.
|
|
1182
1122
|
|
|
1183
|
-
First, tables are by
|
|
1184
|
-
table without affecting the input tables. The only exceptions are
|
|
1185
|
-
~degroup!~ operation, which mutates the receiver table by removing
|
|
1186
|
-
boundaries, and ~force_string!~ (explained above at [[*Forcing String Type][Forcing
|
|
1187
|
-
which forces columns to have the String type despite what
|
|
1188
|
-
rules determine.
|
|
1123
|
+
First, tables are by-and-large immutable objects: each operation creates
|
|
1124
|
+
a new table without affecting the input tables. The only exceptions are
|
|
1125
|
+
the ~degroup!~ operation, which mutates the receiver table by removing
|
|
1126
|
+
its group boundaries, and ~force_string!~ (explained above at [[*Forcing String Type][Forcing
|
|
1127
|
+
String Type]]), which forces columns to have the String type despite what
|
|
1128
|
+
the automatic typing rules determine.
|
|
1189
1129
|
|
|
1190
1130
|
Second, because each operation returns a ~FatTable::Table~ object, the
|
|
1191
1131
|
operations are chainable.
|
|
@@ -1196,9 +1136,9 @@ operations result in marking group boundaries in the result table, others
|
|
|
1196
1136
|
remove group boundaries that may have existed in the input table. Operations
|
|
1197
1137
|
that either create or remove groups will be noted below.
|
|
1198
1138
|
|
|
1199
|
-
Finally, the operations are for the most part patterned on SQL table
|
|
1200
|
-
but when expressions play a role, you write them using ruby
|
|
1201
|
-
SQL.
|
|
1139
|
+
Finally, the operations are, for the most part, patterned on SQL table
|
|
1140
|
+
operations, but when expressions play a role, you write them using ruby
|
|
1141
|
+
syntax rather than SQL.
|
|
1202
1142
|
|
|
1203
1143
|
*** Example Input Tables
|
|
1204
1144
|
For illustration purposes assume that the following tables are read into ruby
|
|
@@ -1597,28 +1537,28 @@ You can set a column to a constant of any of the acceptable types, ~Numeric~,
|
|
|
1597
1537
|
#+begin_example
|
|
1598
1538
|
| Ref | Traded On | Price | Shares | Cost | Today |
|
|
1599
1539
|
|------+------------+--------+--------+--------+------------|
|
|
1600
|
-
| T001 | 2016-11-01 | 7.7000 | 100 | 3.1416 |
|
|
1601
|
-
| T002 | 2016-11-01 | 7.7500 | 200 | 3.1416 |
|
|
1602
|
-
| T003 | 2016-11-01 | 7.5000 | 800 | 3.1416 |
|
|
1603
|
-
| T003 | 2016-11-01 | 7.5000 | 800 | 3.1416 |
|
|
1540
|
+
| T001 | 2016-11-01 | 7.7000 | 100 | 3.1416 | 2026-11-23 |
|
|
1541
|
+
| T002 | 2016-11-01 | 7.7500 | 200 | 3.1416 | 2026-11-23 |
|
|
1542
|
+
| T003 | 2016-11-01 | 7.5000 | 800 | 3.1416 | 2026-11-23 |
|
|
1543
|
+
| T003 | 2016-11-01 | 7.5000 | 800 | 3.1416 | 2026-11-23 |
|
|
1604
1544
|
|------+------------+--------+--------+--------+------------|
|
|
1605
|
-
| T004 | 2016-11-01 | 7.5500 | 6811 | 3.1416 |
|
|
1606
|
-
| T005 | 2016-11-01 | 7.5000 | 4000 | 3.1416 |
|
|
1607
|
-
| T006 | 2016-11-01 | 7.6000 | 1000 | 3.1416 |
|
|
1608
|
-
| T006 | 2016-11-01 | 7.6000 | 1000 | 3.1416 |
|
|
1609
|
-
| T007 | 2016-11-01 | 7.6500 | 200 | 3.1416 |
|
|
1610
|
-
| T008 | 2016-11-01 | 7.6500 | 2771 | 3.1416 |
|
|
1611
|
-
| T009 | 2016-11-01 | 7.6000 | 9550 | 3.1416 |
|
|
1545
|
+
| T004 | 2016-11-01 | 7.5500 | 6811 | 3.1416 | 2026-11-23 |
|
|
1546
|
+
| T005 | 2016-11-01 | 7.5000 | 4000 | 3.1416 | 2026-11-23 |
|
|
1547
|
+
| T006 | 2016-11-01 | 7.6000 | 1000 | 3.1416 | 2026-11-23 |
|
|
1548
|
+
| T006 | 2016-11-01 | 7.6000 | 1000 | 3.1416 | 2026-11-23 |
|
|
1549
|
+
| T007 | 2016-11-01 | 7.6500 | 200 | 3.1416 | 2026-11-23 |
|
|
1550
|
+
| T008 | 2016-11-01 | 7.6500 | 2771 | 3.1416 | 2026-11-23 |
|
|
1551
|
+
| T009 | 2016-11-01 | 7.6000 | 9550 | 3.1416 | 2026-11-23 |
|
|
1612
1552
|
|------+------------+--------+--------+--------+------------|
|
|
1613
|
-
| T010 | 2016-11-01 | 7.5500 | 3175 | 3.1416 |
|
|
1614
|
-
| T011 | 2016-11-02 | 7.4250 | 100 | 3.1416 |
|
|
1615
|
-
| T012 | 2016-11-02 | 7.5500 | 4700 | 3.1416 |
|
|
1616
|
-
| T012 | 2016-11-02 | 7.5500 | 4700 | 3.1416 |
|
|
1617
|
-
| T013 | 2016-11-02 | 7.3500 | 53100 | 3.1416 |
|
|
1553
|
+
| T010 | 2016-11-01 | 7.5500 | 3175 | 3.1416 | 2026-11-23 |
|
|
1554
|
+
| T011 | 2016-11-02 | 7.4250 | 100 | 3.1416 | 2026-11-23 |
|
|
1555
|
+
| T012 | 2016-11-02 | 7.5500 | 4700 | 3.1416 | 2026-11-23 |
|
|
1556
|
+
| T012 | 2016-11-02 | 7.5500 | 4700 | 3.1416 | 2026-11-23 |
|
|
1557
|
+
| T013 | 2016-11-02 | 7.3500 | 53100 | 3.1416 | 2026-11-23 |
|
|
1618
1558
|
|------+------------+--------+--------+--------+------------|
|
|
1619
|
-
| T014 | 2016-11-02 | 7.4500 | 5847 | 3.1416 |
|
|
1620
|
-
| T015 | 2016-11-02 | 7.7500 | 500 | 3.1416 |
|
|
1621
|
-
| T016 | 2016-11-02 | 8.2500 | 100 | 3.1416 |
|
|
1559
|
+
| T014 | 2016-11-02 | 7.4500 | 5847 | 3.1416 | 2026-11-23 |
|
|
1560
|
+
| T015 | 2016-11-02 | 7.7500 | 500 | 3.1416 | 2026-11-23 |
|
|
1561
|
+
| T016 | 2016-11-02 | 8.2500 | 100 | 3.1416 | 2026-11-23 |
|
|
1622
1562
|
#+end_example
|
|
1623
1563
|
|
|
1624
1564
|
**** Custom Instance Variables and Hooks
|
|
@@ -1767,6 +1707,9 @@ input, it adds group boundaries in the output table at those rows where the sort
|
|
|
1767
1707
|
keys change. Thus, in each group, ~:code~ and ~:date~ are the same, and when
|
|
1768
1708
|
either changes, ~order_by~ inserts a group boundary.
|
|
1769
1709
|
|
|
1710
|
+
Sorting with ~order_by~ is stable: keys that are equal maintain the
|
|
1711
|
+
order they had in the unsorted table.
|
|
1712
|
+
|
|
1770
1713
|
*** Order_with
|
|
1771
1714
|
The ~order_with~ method is a convenient combination of ~select~ and
|
|
1772
1715
|
~order_by~. It takes a single string expression as an argument to serve as a
|
|
@@ -2577,7 +2520,6 @@ but ruby data structures, and for them, things such as alignment are irrelevant.
|
|
|
2577
2520
|
|
|
2578
2521
|
*** Available Formatter Output Targets
|
|
2579
2522
|
**** Output Media
|
|
2580
|
-
|
|
2581
2523
|
~FatTable~ supports the following output targets for its tables:
|
|
2582
2524
|
|
|
2583
2525
|
- Text :: form the table with ACSII characters,
|
|
@@ -2625,13 +2567,15 @@ forth are ignored.
|
|
|
2625
2567
|
#+end_example
|
|
2626
2568
|
|
|
2627
2569
|
***** To Org
|
|
2628
|
-
This formatter is designed to format tables in a manner consistent with
|
|
2629
|
-
way tables are drawn within Emacs Org Mode. It also uses nothing by
|
|
2630
|
-
characters to draw the table, but, the
|
|
2631
|
-
by a ~|~ character
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2570
|
+
This formatter is designed to format tables in a manner consistent with
|
|
2571
|
+
the way tables are drawn within Emacs Org Mode. It also uses nothing by
|
|
2572
|
+
ASCII characters to draw the table, but, the outer border lines are
|
|
2573
|
+
represented by a ~|~ character rather than ~+~; inner intersections of
|
|
2574
|
+
lines are still represented as ~+~ as for text. Embelishments such as
|
|
2575
|
+
color, bold, and so forth are ignored. When working in Org Mode, note
|
|
2576
|
+
that Emacs will convert an Array of Arrays into an Org Mode table, so
|
|
2577
|
+
when constructing tables programmatically, it may be better to use the
|
|
2578
|
+
=to_aoa= formatter shown below.
|
|
2635
2579
|
|
|
2636
2580
|
#+begin_SRC ruby
|
|
2637
2581
|
tab_a.to_org
|
|
@@ -2681,7 +2625,7 @@ extent the device supports it.
|
|
|
2681
2625
|
|
|
2682
2626
|
***** To LaTeX
|
|
2683
2627
|
This formatter outputs a table in the form suitable for inclusion in a LaTeX
|
|
2684
|
-
document using the ~
|
|
2628
|
+
document using the ~longtable~ package. Natualy it allows embelishments such
|
|
2685
2629
|
as color and text styles to the full extent of LaTeX's formatting prowess.
|
|
2686
2630
|
|
|
2687
2631
|
#+begin_SRC ruby
|
|
@@ -2733,7 +2677,7 @@ directives as strings in which letters and other characters signify what
|
|
|
2733
2677
|
formatting applies. For example, we may apply the formatting directive 'R,$'
|
|
2734
2678
|
to numbers in a certain part of the table. Each of those characters, and in
|
|
2735
2679
|
some cases a whole substring, is a single directive. They can appear in any
|
|
2736
|
-
order, so
|
|
2680
|
+
order, so =$R=, and =,$R= are equivalent.
|
|
2737
2681
|
|
|
2738
2682
|
Here is a list of all the formatting directives that apply to each cell type:
|
|
2739
2683
|
|
|
@@ -2742,24 +2686,24 @@ For a string element, or any an element of any type (since these are applied
|
|
|
2742
2686
|
after the element has been converted to a String), the following instructions
|
|
2743
2687
|
are valid.
|
|
2744
2688
|
|
|
2745
|
-
- u :: convert the element to all lowercase [default false],
|
|
2746
|
-
- U :: convert the element to all uppercase [default false],
|
|
2747
|
-
- t :: title case the element, that is, upcase the initial letter in
|
|
2689
|
+
- =u= :: convert the element to all lowercase [default false],
|
|
2690
|
+
- =U= :: convert the element to all uppercase [default false],
|
|
2691
|
+
- =t= :: title case the element, that is, upcase the initial letter in
|
|
2748
2692
|
each word and lower case the other letters [default false],
|
|
2749
|
-
- B
|
|
2750
|
-
- I
|
|
2751
|
-
- R :: align the element on the right of the column [default off]
|
|
2752
|
-
- L :: align the element on the left of the column [default on]
|
|
2753
|
-
- C :: align the element in the center of the column [default off]
|
|
2754
|
-
- c[<color_spec>] :: render the element in the given color; the
|
|
2693
|
+
- =B=, =~B= :: make the element bold, or turn off bold [default =~B=]
|
|
2694
|
+
- =I=, =~I= :: make the element italic, or turn off italic [default =~I=]
|
|
2695
|
+
- =R= :: align the element on the right of the column [default off]
|
|
2696
|
+
- =L= :: align the element on the left of the column [default on]
|
|
2697
|
+
- =C= :: align the element in the center of the column [default off]
|
|
2698
|
+
- =c[<color_spec>]= :: render the element in the given color; the =<color_spec>=
|
|
2755
2699
|
can have the form fgcolor, fgcolor.bgcolor, or .bgcolor, to set the
|
|
2756
2700
|
foreground or background colors respectively, and each of those can be an
|
|
2757
2701
|
ANSI or X11 color name in addition to the special color, 'none', which keeps
|
|
2758
2702
|
the output's default color [default none].
|
|
2759
|
-
- _
|
|
2760
|
-
-
|
|
2703
|
+
- =_= :: underline the element, or turn off underline [default off]
|
|
2704
|
+
- =*= :: cause the element to blink, or turn off blink [default off]
|
|
2761
2705
|
|
|
2762
|
-
For example, the directive 'tCc[red.yellow]' would title-case the element,
|
|
2706
|
+
For example, the directive '=tCc[red.yellow]=' would title-case the element,
|
|
2763
2707
|
center it, and color it red on a yellow background. The directives that are
|
|
2764
2708
|
boolean have negating forms so that, for example, if bold is turned on for all
|
|
2765
2709
|
columns of a given type, it can be countermanded in formatting directives for
|
|
@@ -2769,66 +2713,69 @@ particular columns.
|
|
|
2769
2713
|
For a numeric element, all the instructions valid for string are available, in
|
|
2770
2714
|
addition to the following:
|
|
2771
2715
|
|
|
2772
|
-
-
|
|
2773
|
-
|
|
2774
|
-
-
|
|
2775
|
-
|
|
2776
|
-
- m.n :: include at least m digits before the decimal point, padding on the
|
|
2716
|
+
- =,=, =~,= :: insert grouping commas, or do not insert grouping commas (default
|
|
2717
|
+
=~,=),
|
|
2718
|
+
- =$=, =~$= :: format the number as currency according to the locale, or not
|
|
2719
|
+
(default =~$=),
|
|
2720
|
+
- =m.n= :: include at least m digits before the decimal point, padding on the
|
|
2777
2721
|
left with zeroes as needed, and round the number to the n decimal places and
|
|
2778
2722
|
include n digits after the decimal point, padding on the right with zeroes
|
|
2779
2723
|
as needed. If n is negative, the value will be rounded to the left of the
|
|
2780
2724
|
decimal point: e.g., if n is -2, the number will be rounded to the nearest
|
|
2781
|
-
hundred, if -3, to the nearest thousand, etc.
|
|
2782
|
-
- H :: convert the number (assumed to be in units of seconds) to ~HH:MM:SS.ss~
|
|
2725
|
+
hundred, if -3, to the nearest thousand, etc. (default =0.0=)
|
|
2726
|
+
- =H= :: convert the number (assumed to be in units of seconds) to ~HH:MM:SS.ss~
|
|
2783
2727
|
form. So a column that is the result of subtracting two :datetime forms will
|
|
2784
2728
|
result in a :numeric expressed as seconds and can be displayed in hours,
|
|
2785
2729
|
minutes, and seconds with this formatting instruction. If this directive is
|
|
2786
|
-
included, all other numeric directives will be ignored.
|
|
2730
|
+
included, all other numeric directives will be ignored. (default off)
|
|
2787
2731
|
|
|
2788
|
-
For example, the directive
|
|
2732
|
+
For example, the directive =R5.0c[blue]= would right-align the numeric
|
|
2789
2733
|
element, pad it on the left with zeros, and color it blue.
|
|
2790
2734
|
|
|
2791
2735
|
**** DateTime
|
|
2792
2736
|
For a ~DateTime~, all the instructions valid for string are available, in
|
|
2793
2737
|
addition to the following:
|
|
2794
2738
|
|
|
2795
|
-
- d[fmt] :: apply the format to a ~Date~ or a ~DateTime~ that is a whole day,
|
|
2739
|
+
- =d[fmt]= :: apply the format to a ~Date~ or a ~DateTime~ that is a whole day,
|
|
2796
2740
|
that is that has no or zero hour, minute, and second components, where fmt
|
|
2797
2741
|
is a valid format string for ~Date#strftime~, otherwise, the datetime will
|
|
2798
|
-
be formatted as an ISO 8601 string, YYYY-MM-DD
|
|
2799
|
-
- D[fmt] :: apply the format to a datetime that has at least a
|
|
2800
|
-
component where fmt is a valid format string for
|
|
2801
|
-
the datetime will be formatted as an ISO
|
|
2742
|
+
be formatted as an ISO 8601 string, =YYYY-MM-DD=.
|
|
2743
|
+
- =D[fmt]= :: apply the format to a datetime that has at least a
|
|
2744
|
+
non-zero hour component where fmt is a valid format string for
|
|
2745
|
+
~Date#strftime~, otherwise, the datetime will be formatted as an ISO
|
|
2746
|
+
8601 string, =YYYY-MM-DD HH:MM:SS=.
|
|
2802
2747
|
|
|
2803
|
-
For example,
|
|
2804
|
-
22, 1957
|
|
2748
|
+
For example, =c[pink]d[%b %-d, %Y]C=, would format a date element like
|
|
2749
|
+
=Sep 22, 1957=, center it, and color it pink.
|
|
2805
2750
|
|
|
2806
2751
|
**** Boolean
|
|
2807
2752
|
|
|
2808
2753
|
For a boolean cell, all the instructions valid for string are available, in
|
|
2809
2754
|
addition to the following:
|
|
2810
2755
|
|
|
2811
|
-
- Y :: print true as ~Y~ and false as ~N~,
|
|
2812
|
-
- T :: print true as ~T~ and false as ~F~
|
|
2813
|
-
- X :: print true as ~X~ and false as an empty string
|
|
2814
|
-
- b[xxx
|
|
2815
|
-
|
|
2816
|
-
- c[tcolor
|
|
2817
|
-
|
|
2818
|
-
|
|
2756
|
+
- =Y= :: print true as ~Y~ and false as ~N~,
|
|
2757
|
+
- =T= :: print true as ~T~ and false as ~F~ (this is the default),
|
|
2758
|
+
- =X= :: print true as ~X~ and false as an empty string =""=,
|
|
2759
|
+
- =b[<xxx>,<yyy>]= :: print true as the arbitrary string given as
|
|
2760
|
+
~<xxx>~ and false as the arbitrary string given as ~<yyy>~,
|
|
2761
|
+
- =c[<tcolor>,<fcolor>]= :: color a true element with ~<tcolor>~ and a
|
|
2762
|
+
false element with ~<fcolor>~. Each of the colors may be specified in
|
|
2763
|
+
the same manner as colors for strings described above.
|
|
2819
2764
|
|
|
2820
|
-
For example, the directive
|
|
2821
|
-
render a true boolean as ~Yeppers~ colored green on pink and
|
|
2822
|
-
boolean as ~Nope~ colored red on pink. See [[https://www.youtube.com/watch?v=oLdFFD8II8U][Yeppers]] for
|
|
2765
|
+
For example, the directive =b[Yeppers,Nope]c[green.pink,red.pink]=
|
|
2766
|
+
would render a true boolean as ~Yeppers~ colored green on pink and
|
|
2767
|
+
render a false boolean as ~Nope~ colored red on pink. See [[https://www.youtube.com/watch?v=oLdFFD8II8U][Yeppers]] for
|
|
2768
|
+
additional information.
|
|
2823
2769
|
|
|
2824
2770
|
**** NilClass
|
|
2825
2771
|
By default, ~nil~ elements are rendered as blank cells, but you can make them
|
|
2826
2772
|
visible with the following, and in that case, all the formatting instructions
|
|
2827
2773
|
valid for strings are also available:
|
|
2828
2774
|
|
|
2829
|
-
- n[niltext] :: render a
|
|
2775
|
+
- =n[<niltext>]= :: render a =nil= item with the given arbitrary string
|
|
2776
|
+
=<niltext>= (default =""=).
|
|
2830
2777
|
|
|
2831
|
-
For example, you might want to use
|
|
2778
|
+
For example, you might want to use =n[-]Cc[purple]= to make =nil=s visible as a
|
|
2832
2779
|
centered purple hyphen.
|
|
2833
2780
|
|
|
2834
2781
|
*** The ~format~ and ~format_for~ methods
|
|
@@ -2893,19 +2840,19 @@ be right-aligned, but the headers are unaffected by it. The ~format_for~ the
|
|
|
2893
2840
|
All the other cells in the table, namely the cells in the ~:join_date~ column,
|
|
2894
2841
|
had the default formatting applied.
|
|
2895
2842
|
|
|
2896
|
-
**** Table
|
|
2843
|
+
**** Locations within a Table
|
|
2897
2844
|
In the ~format_for~ formatting method, the first argument names a "location."
|
|
2898
2845
|
The table is divided into several locations for which separate formatting
|
|
2899
2846
|
directives may be given. These locations are identified by the following
|
|
2900
2847
|
symbols:
|
|
2901
2848
|
|
|
2902
|
-
-
|
|
2903
|
-
-
|
|
2904
|
-
-
|
|
2905
|
-
-
|
|
2906
|
-
of the header, footers, or
|
|
2907
|
-
-
|
|
2908
|
-
-
|
|
2849
|
+
- =:header= :: the first row of the output table containing the headers,
|
|
2850
|
+
- =:footer= :: all rows of the table's footers,
|
|
2851
|
+
- =:gfooter= :: all rows of the table's group footers,
|
|
2852
|
+
- =:body= :: all the data rows of the table, that is, those that are neither part
|
|
2853
|
+
of the header, footers, or group footers,
|
|
2854
|
+
- =:bfirst= :: the first row of the table's body, and
|
|
2855
|
+
- =:gfirst= :: the first row in each group in the table's body.
|
|
2909
2856
|
|
|
2910
2857
|
**** Location priority
|
|
2911
2858
|
Formatting for any given cell depends on its location in the table. The
|
|
@@ -2979,11 +2926,10 @@ but not for other nils, such as in the last row of the ~:join_date~ column.
|
|
|
2979
2926
|
*** Footers
|
|
2980
2927
|
**** Adding Footers
|
|
2981
2928
|
You can call the ~foot~, ~gfoot~, ~footer,~ or ~gfooter~, methods on
|
|
2982
|
-
~Formatter~ objects to add footers and group footers.
|
|
2983
|
-
methods return
|
|
2984
|
-
values
|
|
2985
|
-
|
|
2986
|
-
footer computed. Their signatures are:
|
|
2929
|
+
~Formatter~ objects to add footers and group footers. All of these
|
|
2930
|
+
methods return the ~FatTable::Footer~ object so constructed. It can be
|
|
2931
|
+
used to access the values and other attributes of the footer
|
|
2932
|
+
computed. Their signatures are:
|
|
2987
2933
|
|
|
2988
2934
|
- ~foot(label: label, label_col: nil, **agg_cols)~ :: where ~label~ is a label
|
|
2989
2935
|
to be placed in the column with header ~label_col~, or, if ommitted, in the
|
|
@@ -3074,20 +3020,21 @@ When adding a footer with the above methods, you can specify an aggregator for
|
|
|
3074
3020
|
each column named in the ~agg_cols~ parameter. There are several candidates
|
|
3075
3021
|
for what you can use for an aggregator:
|
|
3076
3022
|
|
|
3077
|
-
- Symbol :: one of the following built-in aggregators:
|
|
3078
|
-
|
|
3079
|
-
|
|
3023
|
+
- Symbol :: one of the following built-in aggregators: ~:first~,
|
|
3024
|
+
~:last~, ~:range~, ~:sum~, ~:count~, ~:min~, ~:max~, ~:avg~, ~:var~,
|
|
3025
|
+
~:pvar~, ~:dev~, ~:pdev~, ~:any?~, ~:all?~, ~:none?~, and ~:one?~.
|
|
3080
3026
|
+ The symbols ending in a question mark are valid only for boolean columns;
|
|
3081
|
-
+
|
|
3082
|
-
+
|
|
3083
|
-
+
|
|
3084
|
-
+
|
|
3085
|
-
In the case of datetime columns, these
|
|
3086
|
-
julian date numbers, perform the
|
|
3087
|
-
to a datetime object.
|
|
3088
|
-
Apart from the built-in aggregators, you could define your own by
|
|
3089
|
-
FatTable::Column class and adding a suitable instance
|
|
3090
|
-
case, the symbol could also refer to the method you
|
|
3027
|
+
+ ~:count~, ~:first~, and ~:last~ work with any column type,
|
|
3028
|
+
+ ~:min~, ~:max~, and ~:range~ work with all types except boolean;
|
|
3029
|
+
+ ~:sum~, works only with numeric columns, and
|
|
3030
|
+
+ ~:avg~, ~:var~, ~:dev~, ~:pvar~, and ~:pdev~ work with numeric or
|
|
3031
|
+
datetime columns. In the case of datetime columns, these
|
|
3032
|
+
aggregators convert the dates to julian date numbers, perform the
|
|
3033
|
+
calculation, then convert the result back to a datetime object.
|
|
3034
|
+
Apart from the built-in aggregators, you could define your own by
|
|
3035
|
+
opening the ~FatTable::Column~ class and adding a suitable instance
|
|
3036
|
+
method. In that case, the symbol could also refer to the method you
|
|
3037
|
+
defined.
|
|
3091
3038
|
- String :: using a string as an aggrgegator can result in:
|
|
3092
3039
|
+ the string being converted to an object matching the type of the column
|
|
3093
3040
|
(for example, using '$1,888' in a numeric column puts the constant number
|
|
@@ -3096,9 +3043,9 @@ for what you can use for an aggregator:
|
|
|
3096
3043
|
+ if the string cannot be parsed as a valid object matching the column's
|
|
3097
3044
|
type, it is placed literally in the footer field (for example, using
|
|
3098
3045
|
'(estimated)' can be used to add additional information to the footer)
|
|
3099
|
-
- Ruby object :: you can put a
|
|
3100
|
-
object in a datetime footer field, or a true or
|
|
3101
|
-
field;
|
|
3046
|
+
- Ruby object :: you can put a ~Numeric~ in a numeric footer field, a
|
|
3047
|
+
~Date~ or ~DateTime~ object in a datetime footer field, or a true or
|
|
3048
|
+
false in a boolean footer field;
|
|
3102
3049
|
- A Lambda :: finally, you can provide a lambda for performing arbitrary
|
|
3103
3050
|
calculations and placing the result in the footer field. The number of
|
|
3104
3051
|
arguments the lambda takes can vary:
|
|
@@ -3267,7 +3214,7 @@ column.
|
|
|
3267
3214
|
+-------------+-------+-----+------------+--------+-------------+
|
|
3268
3215
|
| Average | | 31 | | 31,429 | 29-DEC-2005 |
|
|
3269
3216
|
+-------------+-------+-----+------------+--------+-------------+
|
|
3270
|
-
| Report Date | | 8 | | |
|
|
3217
|
+
| Report Date | | 8 | | | 23-NOV-2026 |
|
|
3271
3218
|
+=============+=======+=====+============+========+=============+
|
|
3272
3219
|
#+end_example
|
|
3273
3220
|
|
|
@@ -3297,7 +3244,7 @@ But it can be any type. Here we pick a lottery winner from the employee ids.
|
|
|
3297
3244
|
+----------------+-------+-----+------------+--------+-------------+
|
|
3298
3245
|
| Average | | 31 | | 31,429 | 29-DEC-2005 |
|
|
3299
3246
|
+----------------+-------+-----+------------+--------+-------------+
|
|
3300
|
-
| Lottery Winner | | 8 | | |
|
|
3247
|
+
| Lottery Winner | | 8 | | | 4 |
|
|
3301
3248
|
+================+=======+=====+============+========+=============+
|
|
3302
3249
|
#+end_example
|
|
3303
3250
|
|
data/lib/core_ext/array.rb
CHANGED
|
@@ -22,7 +22,7 @@ class Array
|
|
|
22
22
|
compact.select { |i| i.is_a?(Date) || i.is_a?(DateTime) || i.is_a?(Time) }
|
|
23
23
|
.map(&:to_datetime)
|
|
24
24
|
elsif typ == 'Numeric'
|
|
25
|
-
compact.
|
|
25
|
+
compact.grep(Numeric)
|
|
26
26
|
elsif typ == 'String'
|
|
27
27
|
map(&:to_s)
|
|
28
28
|
elsif typ == 'NilClass'
|
data/lib/fat_table/evaluator.rb
CHANGED
|
@@ -51,13 +51,12 @@ module FatTable
|
|
|
51
51
|
# when a string gets into an otherwise numeric column because the column
|
|
52
52
|
# is set to tolerant.
|
|
53
53
|
#
|
|
54
|
-
# rubocop:disable Security/Eval
|
|
54
|
+
# rubocop:disable-next Security/Eval
|
|
55
55
|
def evaluate(expr = '', locals: {})
|
|
56
56
|
eval(expr, local_vars(binding, locals))
|
|
57
57
|
rescue NoMethodError, TypeError
|
|
58
58
|
nil
|
|
59
59
|
end
|
|
60
|
-
# rubocop:enable Security/Eval
|
|
61
60
|
|
|
62
61
|
private
|
|
63
62
|
|
|
@@ -1208,9 +1208,8 @@ module FatTable
|
|
|
1208
1208
|
# If this Formatter targets a ruby data structure (e.g., AoaFormatter), we
|
|
1209
1209
|
# eval the string to get the object.
|
|
1210
1210
|
#
|
|
1211
|
-
# rubocop:disable Security/Eval
|
|
1211
|
+
# rubocop:disable-next Security/Eval
|
|
1212
1212
|
evaluate? ? eval(result) : result
|
|
1213
|
-
# rubocop:enable Security/Eval
|
|
1214
1213
|
end
|
|
1215
1214
|
|
|
1216
1215
|
private
|
data/lib/fat_table/table.rb
CHANGED
|
@@ -821,6 +821,7 @@ module FatTable
|
|
|
821
821
|
# Return a new Table sorting the rows of this Table on the possibly multiple
|
|
822
822
|
# keys given in +sort_heads+ as an Array of Symbols. Append a ! to the
|
|
823
823
|
# symbol name to indicate reverse sorting on that column.
|
|
824
|
+
# Rows with equal sort keys retain their original order in either direction.
|
|
824
825
|
#
|
|
825
826
|
# tab.order_by(:ref, :date) => sorted table
|
|
826
827
|
# tab.order_by(:date!) => reverse sort on :date
|
|
@@ -830,7 +831,7 @@ module FatTable
|
|
|
830
831
|
def order_by(*sort_heads)
|
|
831
832
|
# Sort the rows in order and add to new_rows.
|
|
832
833
|
key_hash = partition_sort_keys(sort_heads)
|
|
833
|
-
new_rows = rows.sort
|
|
834
|
+
new_rows = rows.each_with_index.sort { |(r1, index1), (r2, index2)|
|
|
834
835
|
# Set the sort keys based on direction
|
|
835
836
|
key1 = []
|
|
836
837
|
key2 = []
|
|
@@ -850,8 +851,9 @@ module FatTable
|
|
|
850
851
|
# If there are any nils, <=> will return nil, and we have to use the
|
|
851
852
|
# special comparison method, compare_with_nils, instead.
|
|
852
853
|
result = (key1 <=> key2)
|
|
853
|
-
result
|
|
854
|
-
|
|
854
|
+
result = compare_with_nils(key1, key2) if result.nil?
|
|
855
|
+
result.zero? ? index1 <=> index2 : result
|
|
856
|
+
}.map(&:first)
|
|
855
857
|
|
|
856
858
|
# Add the new_rows to the table, but mark a group boundary at the points
|
|
857
859
|
# where the sort key changes value. NB: I use self.class.new here
|
data/lib/fat_table/version.rb
CHANGED