fat_table 0.9.9 → 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.
data/README.org CHANGED
@@ -2,43 +2,37 @@
2
2
  #+OPTIONS: toc:4
3
3
  #+LATEX_HEADER: \usepackage[margin=0.75in]{geometry}
4
4
  #+LATEX_HEADER: \usepackage[utf8]{inputenc}
5
- #+PROPERTY: header-args:ruby :colnames no :session readme :hlines yes :exports both
6
- #+PROPERTY: header-args:sh :exports code
7
5
  #+STARTUP: inlineimages
6
+ #+PROPERTY: header-args:ruby :results value :colnames no :hlines yes :exports both :dir "./"
7
+ #+PROPERTY: header-args:ruby :wrap example :session fat_table_session
8
+ #+PROPERTY: header-args:ruby+ :ruby "bundle exec irb"
9
+ #+PROPERTY: header-args:ruby+ :prologue "$:.unshift('./lib') unless $:.first == './lib'; require 'fat_table'" :eval yes
10
+ #+PROPERTY: header-args:sh :exports code :eval no
11
+ #+PROPERTY: header-args:bash :exports code :eval no
8
12
 
9
- #+begin_comment
10
- Notes on producing this README.
13
+ # gem_docs:version begin
14
+ Version: 1.1.0
15
+ # gem_docs:version end
11
16
 
12
- 1. Result blocks won't be rendered on Github if the #+RESULTS: tag is left
13
- over the results block, so manually delete them.
14
17
 
15
- 2. Make sure that the current version of the gem is geting loaded when running
16
- the code blocks. rbenv-use-corresponding helps here.
17
- #+end_comment
18
18
 
19
- #+BEGIN_COMMENT
20
- This is for markdown output:
21
-
22
- [![Build Status](https://travis-ci.org/ddoherty03/fat_table.svg?branch=master)](https://travis-ci.org/ddoherty03/fat_table)
23
-
24
- The following is for org.
25
- #+END_COMMENT
26
-
27
- [[https://travis-ci.org/ddoherty03/fat_table.svg?branch=master]]
19
+ #+BEGIN_EXPORT markdown
20
+ [![CI](https://github.com/ddoherty03/fat_table/actions/workflows/ruby-with-dbs.yml/badge.svg)](
21
+ https://github.com/ddoherty03/fat_table/actions/workflows/ruby-with-dbs.yml
22
+ )
23
+ #+END_EXPORT
28
24
 
29
25
  * Version
30
- #+begin_src ruby :wrap EXAMPLE
31
- require 'fat_table'
26
+ #+begin_src ruby
32
27
  "Current version is: #{FatTable::VERSION}"
33
28
  #+end_src
34
29
 
35
30
  #+RESULTS:
36
- #+begin_EXAMPLE
37
- Current version is: 0.6.3
38
- #+end_EXAMPLE
31
+ #+begin_example
32
+ Current version is: 1.1.0
33
+ #+end_example
39
34
 
40
35
  * Introduction
41
-
42
36
  ~FatTable~ is a gem that treats tables as a data type. It provides methods for
43
37
  constructing tables from a variety of sources, building them row-by-row,
44
38
  extracting rows, columns, and cells, and performing aggregate operations on
@@ -79,10 +73,90 @@ org-mode buffer as an org-table, ready for processing by other code blocks.
79
73
  - [[#quick-start][Quick Start]]
80
74
  - [[#a-word-about-the-examples][A Word About the Examples]]
81
75
  - [[#anatomy-of-a-table][Anatomy of a Table]]
76
+ - [[#columns][Columns]]
77
+ - [[#type-keywords-arguments][Type Keywords Arguments]]
78
+ - [[#headers][Headers]]
79
+ - [[#groups][Groups]]
82
80
  - [[#constructing-tables][Constructing Tables]]
81
+ - [[#empty-tables][Empty Tables]]
82
+ - [[#without-headers][Without Headers]]
83
+ - [[#with-headers][With Headers]]
84
+ - [[#forcing-string-type][Forcing String Type]]
85
+ - [[#from-csv-or-org-mode-files-or-strings][From CSV or Org Mode files or strings]]
86
+ - [[#from-arrays-of-arrays][From Arrays of Arrays]]
87
+ - [[#in-ruby-code][In Ruby Code]]
88
+ - [[#in-emacs-org-files][In Emacs Org Files]]
89
+ - [[#from-arrays-of-hashes][From Arrays of Hashes]]
90
+ - [[#from-sql-queries][From SQL queries]]
91
+ - [[#marking-groups-in-input][Marking Groups in Input]]
92
+ - [[#manually][Manually]]
93
+ - [[#when-reading-in-tables][When Reading in Tables]]
83
94
  - [[#accessing-parts-of-tables][Accessing Parts of Tables]]
95
+ - [[#rows][Rows]]
96
+ - [[#columns-1][Columns]]
97
+ - [[#cells][Cells]]
98
+ - [[#other-table-attributes][Other table attributes]]
84
99
  - [[#operations-on-tables][Operations on Tables]]
100
+ - [[#example-input-tables][Example Input Tables]]
101
+ - [[#select][Select]]
102
+ - [[#selecting-existing-columns-also-of-omni][Selecting Existing Columns (Also of :omni)]]
103
+ - [[#copying-and-renaming-existing-columns][Copying and Renaming Existing Columns.]]
104
+ - [[#adding-new-computed-columns][Adding New Computed Columns]]
105
+ - [[#adding-constant-strings-and-other-types-in-select][Adding Constant Strings and Other Types in select]]
106
+ - [[#custom-instance-variables-and-hooks][Custom Instance Variables and Hooks]]
107
+ - [[#argument-order-and-boundaries][Argument Order and Boundaries]]
108
+ - [[#where][Where]]
109
+ - [[#order_by][Order_by]]
110
+ - [[#order_with][Order_with]]
111
+ - [[#group_by][Group_by]]
112
+ - [[#join][Join]]
113
+ - [[#join-types][Join Types]]
114
+ - [[#join-expressions][Join Expressions]]
115
+ - [[#join-examples][Join Examples]]
116
+ - [[#inner-joins][Inner Joins]]
117
+ - [[#left-and-right-joins][Left and Right Joins]]
118
+ - [[#full-join][Full Join]]
119
+ - [[#cross-join][Cross Join]]
120
+ - [[#set-operations][Set Operations]]
121
+ - [[#unions][Unions]]
122
+ - [[#intersections][Intersections]]
123
+ - [[#set-differences-with-except][Set Differences with Except]]
124
+ - [[#uniq-aka-distinct][Uniq (aka Distinct)]]
125
+ - [[#remove-groups-with-degroup][Remove groups with degroup!]]
85
126
  - [[#formatting-tables][Formatting Tables]]
127
+ - [[#available-formatter-output-targets][Available Formatter Output Targets]]
128
+ - [[#output-media][Output Media]]
129
+ - [[#examples][Examples]]
130
+ - [[#to-text][To Text]]
131
+ - [[#to-org][To Org]]
132
+ - [[#to-term][To Term]]
133
+ - [[#to-latex][To LaTeX]]
134
+ - [[#to-aoa-array-of-arrays][To AoA (Array of Arrays)]]
135
+ - [[#to-aoh-array-of-hashes][To AoH (Array of Hashes)]]
136
+ - [[#formatting-directives][Formatting Directives]]
137
+ - [[#all-types-as-strings][All Types as Strings]]
138
+ - [[#numeric][Numeric]]
139
+ - [[#datetime][DateTime]]
140
+ - [[#boolean][Boolean]]
141
+ - [[#nilclass][NilClass]]
142
+ - [[#the-format-and-format_for-methods][The ~format~ and ~format_for~ methods]]
143
+ - [[#locations-within-a-table][Locations within a Table]]
144
+ - [[#location-priority][Location priority]]
145
+ - [[#type-and-column-priority][Type and Column priority]]
146
+ - [[#footers][Footers]]
147
+ - [[#adding-footers][Adding Footers]]
148
+ - [[#dynamic-labels][Dynamic Labels]]
149
+ - [[#aggregators][Aggregators]]
150
+ - [[#footer-objects][Footer objects]]
151
+ - [[#footer-examples][Footer Examples]]
152
+ - [[#built-in-aggregators][Built-in Aggregators]]
153
+ - [[#string-aggregators][String Aggregators]]
154
+ - [[#ruby-objects][Ruby Objects]]
155
+ - [[#lambdas][Lambdas]]
156
+ - [[#invoking-formatters][Invoking Formatters]]
157
+ - [[#by-instantiating-a-formatter][By Instantiating a Formatter]]
158
+ - [[#by-using-fattable-module-level-method-calls][By Using ~FatTable~ module-level method calls]]
159
+ - [[#by-calling-methods-on-table-objects][By Calling Methods on Table Objects]]
86
160
  - [[#development][Development]]
87
161
  - [[#contributing][Contributing]]
88
162
 
@@ -93,16 +167,28 @@ Add this line to your application's Gemfile:
93
167
  gem 'fat_table'
94
168
  #+END_SRC
95
169
 
170
+ #+RESULTS:
171
+ #+begin_example
172
+ true
173
+ #+end_example
174
+
96
175
  Or, something like this in your gemspec file:
97
176
  #+begin_SRC ruby :exports code
98
177
  gem.add_runtime_dependency 'fat_table'
99
178
  #+end_SRC
100
179
 
180
+ #+RESULTS:
181
+ #+begin_example
182
+ #<ArgumentError: wrong number of arguments (given 0, expected 1+)>
183
+ #+end_example
184
+
101
185
  And then execute:
102
186
  #+BEGIN_SRC sh
103
187
  $ bundle
104
188
  #+END_SRC
105
189
 
190
+ #+RESULTS:
191
+
106
192
  ** Manually install
107
193
  Or install it yourself as:
108
194
 
@@ -110,6 +196,8 @@ Or install it yourself as:
110
196
  $ gem install fat_table
111
197
  #+END_SRC
112
198
 
199
+ #+RESULTS:
200
+
113
201
  ** Require
114
202
  Somewhere in your code, make sure that =FatTable= is required:
115
203
  #+begin_src ruby :exports code :results silent
@@ -152,11 +240,11 @@ compund key, select all columns but add a column, :ref, for the row number,
152
240
  and finally re-order the columns with a final select.
153
241
 
154
242
  #+BEGIN_SRC ruby :results silent :exports code
155
- table = FatTable.from_aoa(data) \
156
- .where('shares > 2000') \
157
- .order_by(:date, :code) \
243
+ table = FatTable.from_aoa(data)
244
+ .where('shares > 2000')
245
+ .order_by(:date, :code)
158
246
  .select(:date, :code, :shares,
159
- :price, :ok, ref: '@row') \
247
+ :price, :ok, ref: '@row')
160
248
  .select(:ref, :date, :code,
161
249
  :shares, :price, :ok)
162
250
  #+END_SRC
@@ -203,50 +291,40 @@ We can format the table constructed above.
203
291
  end
204
292
  #+END_SRC
205
293
 
294
+ #+RESULTS:
206
295
  #+begin_example
207
- +=========+============+======+=============+==========+====+
208
- | Ref | Date | Code | Shares | Price | Ok |
209
- +---------+------------+------+-------------+----------+----+
210
- | 1 | 2013-05-02 | P | 118,186.4 | $11.8500 | Y |
211
- | 2 | 2013-05-02 | P | 795,546.2 | 1.1850 | Y |
212
- +---------+------------+------+-------------+----------+----+
213
- | Avg | | | 456,866.3 | 6.5175 | |
214
- +---------+------------+------+-------------+----------+----+
215
- | 3 | 2013-05-20 | S | 5,046.0 | 28.2804 | N |
216
- | 4 | 2013-05-20 | S | 35,742.5 | 28.3224 | Y |
217
- | 5 | 2013-05-20 | S | 14,003.5 | 28.6383 | Y |
218
- +---------+------------+------+-------------+----------+----+
219
- | Avg | | | 18,264.0 | 28.4137 | |
220
- +---------+------------+------+-------------+----------+----+
221
- | 6 | 2013-05-23 | S | 3,364.0 | 27.1083 | Y |
222
- | 7 | 2013-05-23 | S | 16,780.5 | 25.1749 | Y |
223
- | 8 | 2013-05-23 | S | 9,694.2 | 26.8015 | N |
224
- +---------+------------+------+-------------+----------+----+
225
- | Avg | | | 9,946.2 | 26.3616 | |
226
- +---------+------------+------+-------------+----------+----+
227
- | 9 | 2013-05-29 | S | 6,601.9 | 24.7790 | N |
228
- | 10 | 2013-05-29 | S | 5,659.5 | 24.7464 | Y |
229
- | 11 | 2013-05-29 | S | 6,686.0 | 24.5802 | Y |
230
- +---------+------------+------+-------------+----------+----+
231
- | Avg | | | 6,315.8 | 24.7019 | |
232
- +---------+------------+------+-------------+----------+----+
233
- | 12 | 2013-05-30 | S | 2,808.5 | 25.0471 | Y |
234
- +---------+------------+------+-------------+----------+----+
235
- | Avg | | | 2,808.5 | 25.0471 | |
236
- +---------+------------+------+-------------+----------+----+
237
- | Average | | | 85,009.9 | $23.0428 | |
238
- +---------+------------+------+-------------+----------+----+
239
- | Total | | | 1,020,119.1 | | |
240
- +=========+============+======+=============+==========+====+
296
+ +============+======+=============+=============+==========+=========+====+
297
+ | Date | Code | Raw | Shares | Price | Info | Ok |
298
+ +------------+------+-------------+-------------+----------+---------+----+
299
+ | 2013-05-29 | S | 15700.0000 | 6,601.9 | $24.7790 | ENTITY3 | N |
300
+ | 2013-05-02 | P | 118186.4000 | 118,186.4 | 11.8500 | ENTITY1 | Y |
301
+ | 2013-05-20 | S | 12000.0000 | 5,046.0 | 28.2804 | ENTITY3 | N |
302
+ | 2013-05-23 | S | 8000.0000 | 3,364.0 | 27.1083 | ENTITY3 | Y |
303
+ | 2013-05-23 | S | 39906.0000 | 16,780.5 | 25.1749 | ENTITY3 | Y |
304
+ | 2013-05-20 | S | 85000.0000 | 35,742.5 | 28.3224 | ENTITY3 | Y |
305
+ | 2013-05-02 | P | 795546.2000 | 795,546.2 | 1.1850 | ENTITY1 | Y |
306
+ | 2013-05-29 | S | 13459.0000 | 5,659.5 | 24.7464 | ENTITY3 | Y |
307
+ | 2013-05-20 | S | 33302.0000 | 14,003.5 | 28.6383 | ENTITY3 | Y |
308
+ | 2013-05-29 | S | 15900.0000 | 6,685.10 | 24.5802 | ENTITY3 | Y |
309
+ | 2013-05-30 | S | 6679.0000 | 2,808.5 | 25.0471 | ENTITY3 | Y |
310
+ | 2013-05-23 | S | 23054.0000 | 9,694.2 | 26.8015 | ENTITY3 | N |
311
+ +------------+------+-------------+-------------+----------+---------+----+
312
+ | Avg | | | 85,009.9 | 23.0428 | | |
313
+ +------------+------+-------------+-------------+----------+---------+----+
314
+ | Average | | | 85,009.9 | $23.0428 | | |
315
+ +------------+------+-------------+-------------+----------+---------+----+
316
+ | Total | | | 1,020,119.1 | | | |
317
+ +============+======+=============+=============+==========+=========+====+
241
318
  #+end_example
242
319
 
243
320
  For the text format above, we were wasting our breath specifying bold styling
244
321
  since there is no way to make that happen in plain ASCII text. But with
245
322
  LaTeX, bold is doable. The output of the following code block is being
246
- written to a file =examples/quicktable.tex= which is then =\included=-ed in a
247
- simple wrapper file, =examples/quick.tex= so it can be compiled by LaTeX.
323
+ written to a file =spec/example_files/quicktable.tex= which is then
324
+ =\included=-ed in a simple wrapper file, =spec/example_files/quick.tex=
325
+ so it can be compiled by LaTeX.
248
326
 
249
- #+BEGIN_SRC ruby :results file :file "examples/quicktable.tex"
327
+ #+BEGIN_SRC ruby :results file :file "spec/example_files/quicktable.tex"
250
328
  table.to_latex do |fmt|
251
329
  fmt.gfooter('Avg', shares: :avg, price: :avg)
252
330
  fmt.avg_footer(:price, :shares)
@@ -260,26 +338,32 @@ simple wrapper file, =examples/quick.tex= so it can be compiled by LaTeX.
260
338
  end
261
339
  #+END_SRC
262
340
 
263
- #+begin_EXAMPLE
264
- [[file:examples/quicktable.tex]]
265
- #+end_EXAMPLE
341
+ #+RESULTS:
342
+ #+begin_example
343
+ [[file:spec/example_files/quicktable.tex]]
344
+ #+end_example
345
+
346
+ [[file:spec/example_files/quicktable.tex]]
266
347
 
267
348
  These commands run pdflatex on the result twice to get the table aligned
268
349
  properly.
269
350
  #+begin_src sh :results silent
270
- cd examples
351
+ cd spec/example_files
271
352
  pdflatex quick.tex
272
353
  pdflatex quick.tex
273
354
  #+end_src
274
355
 
275
356
  And we convert the =PDF= into a smaller image for display:
276
357
  #+begin_src sh :results verbatim
277
- cd examples
358
+ cd spec/example_files
278
359
  pdftoppm -png quick.pdf >quick.png
279
- convert quick.png -resize 600x800 quick_small.png
360
+ magick quick.png -resize 600x800 quick_small.png
280
361
  #+end_src
281
362
 
282
- [[file:examples/quick_small.png]]
363
+ #+RESULTS:
364
+
365
+ [[file:spec/example_files/quick_small.png]]
366
+
283
367
 
284
368
  ** A Word About the Examples
285
369
  When you install the ~fat_table~ gem, you have access to a program ~ft_console~,
@@ -392,7 +476,7 @@ The type string can be anything that starts with 'dat', 'num', 'boo', or
392
476
  that is, it remains open for automatic typing.
393
477
 
394
478
  The strictness of requiring all items to be of the same type can be relaxed by
395
- declaring a column to be "tolerant." You can do so by adding a '~' to the end
479
+ declaring a column to be "tolerant." You can do so by adding a =~= to the end
396
480
  of a keyword type specifier in the table constructor. In the above example,
397
481
  if we wanted to allow strings to be mixed up with the numeric prices, we would
398
482
  use the following:
@@ -493,18 +577,19 @@ Column, ~:a~ and ~:b~ will have type Numeric, column ~:c~ will have type
493
577
  have an open type. Notice that dates in the input can be wrapped in brackets as
494
578
  in org-mode time stamps.
495
579
 
496
- #+BEGIN_SRC ruby :wrap EXAMPLE
580
+ #+BEGIN_SRC ruby
497
581
  tab.to_text
498
582
  #+END_SRC
499
583
 
500
- #+begin_EXAMPLE
501
- +======+======+============+===+===+
502
- | A | B | C | D | E |
503
- +------+------+------------+---+---+
504
- | 1 | 2 | 2017-01-21 | F | |
505
- | 3.14 | 2.17 | 2016-01-21 | T | |
506
- +======+======+============+===+===+
507
- #+end_EXAMPLE
584
+ #+RESULTS:
585
+ #+begin_example
586
+ +========+========+============+===+===+
587
+ | A | B | C | D | E |
588
+ +--------+--------+------------+---+---+
589
+ | 1 | 2 | 2017-01-21 | F | |
590
+ | 3.1400 | 2.1700 | 2016-01-21 | T | |
591
+ +========+========+============+===+===+
592
+ #+end_example
508
593
 
509
594
  You can continue to add rows to the table:
510
595
  #+BEGIN_SRC ruby :results silent
@@ -519,50 +604,48 @@ for which no key was give are assigned ~nil~ as well:
519
604
  tab.to_text
520
605
  #+END_SRC
521
606
 
522
- #+begin_EXAMPLE
523
- +======+======+============+===+===+=========+
524
- | A | B | C | D | E | F |
525
- +------+------+------------+---+---+---------+
526
- | 1 | 2 | 2017-01-21 | F | | |
527
- | 3.14 | 2.17 | 2016-01-21 | T | | |
528
- +------+------+------------+---+---+---------+
529
- | 3/5 | | | | | 335/113 |
530
- +======+======+============+===+===+=========+
531
- #+end_EXAMPLE
607
+ #+RESULTS:
608
+ #+begin_example
609
+ +========+========+============+===+===+=========+
610
+ | A | B | C | D | E | F |
611
+ +--------+--------+------------+---+---+---------+
612
+ | 1 | 2 | 2017-01-21 | F | | |
613
+ | 3.1400 | 2.1700 | 2016-01-21 | T | | |
614
+ | 3/5 | | | | | 335/113 |
615
+ +========+========+============+===+===+=========+
616
+ #+end_example
532
617
 
533
618
  **** With Headers
534
-
535
619
  Alternatively, you can specify the headers at the outset, in which case,
536
620
  headers in added rows that do not match any of the initial headers cause new
537
621
  columns to be created:
538
622
 
539
- #+BEGIN_SRC ruby :wrap EXAMPLE :results raw
623
+ #+BEGIN_SRC ruby :results raw
540
624
  require 'fat_table'
541
625
  tab = FatTable.new(:a, 'b', 'C', :d)
542
626
  tab.headers
543
627
  #+END_SRC
544
628
 
545
- #+begin_EXAMPLE
629
+ #+RESULTS:
630
+ #+begin_example
546
631
  [:a, :b, :c, :d]
547
- #+end_EXAMPLE
632
+ #+end_example
548
633
 
549
- #+begin_src ruby :wrap EXAMPLE
634
+ #+begin_src ruby
550
635
  tab << { a: 1, b: 2, c: "<2017-01-21>", d: 'f', e: '' }
551
636
  tab << { a: 3.14, b: 2.17, c: '[2016-01-21 Thu]', d: 'Y', e: nil }
552
637
  tab.to_text
553
638
  #+end_src
554
639
 
555
- #+begin_EXAMPLE
556
- +======+======+============+===+===+
557
- | A | B | C | D | E |
558
- +------+------+------------+---+---+
559
- | 1 | 2 | 2017-01-21 | F | |
560
- | 3.14 | 2.17 | 2016-01-21 | T | |
561
- +------+------+------------+---+---+
562
- | 1 | 2 | 2017-01-21 | F | |
563
- | 3.14 | 2.17 | 2016-01-21 | T | |
564
- +======+======+============+===+===+
565
- #+end_EXAMPLE
640
+ #+RESULTS:
641
+ #+begin_example
642
+ +========+========+============+===+===+
643
+ | A | B | C | D | E |
644
+ +--------+--------+------------+---+---+
645
+ | 1 | 2 | 2017-01-21 | F | |
646
+ | 3.1400 | 2.1700 | 2016-01-21 | T | |
647
+ +========+========+============+===+===+
648
+ #+end_example
566
649
 
567
650
  **** Forcing String Type
568
651
 
@@ -572,7 +655,7 @@ appearance. Think, for example, of zip codes. As mentioned above, when a
572
655
  table is contructed, you can designate a 'String' type for a column by
573
656
  using a keyword parameter.
574
657
 
575
- #+begin_src ruby :wrap EXAMPLE
658
+ #+begin_src ruby
576
659
  require 'fat_table'
577
660
  tab = FatTable.new(:a, 'b!', 'C', :d, :zip, zip: 'str')
578
661
  tab << { a: 1, b: 2, c: "<2017-01-21>", d: 'f', e: '', zip: 18552 }
@@ -583,23 +666,24 @@ using a keyword parameter.
583
666
  tab.to_text
584
667
  #+end_src
585
668
 
586
- #+begin_EXAMPLE
587
- +===+===+============+===+=============+===+
588
- | A | B | C | D | Zip | E |
589
- +---+---+------------+---+-------------+---+
590
- | 1 | 2 | 2017-01-21 | F | 18552 | |
591
- | 3 | 2 | 2016-01-21 | T | | |
592
- | | | | | 01879--7884 | |
593
- | | | | | 90210 | |
594
- | | | | | | |
595
- +===+===+============+===+=============+===+
596
- #+end_EXAMPLE
669
+ #+RESULTS:
670
+ #+begin_example
671
+ +========+========+============+===+=============+===+
672
+ | A | B | C | D | Zip | E |
673
+ +--------+--------+------------+---+-------------+---+
674
+ | 1 | 2 | 2017-01-21 | F | 18552 | |
675
+ | 3.1400 | 2.1700 | 2016-01-21 | T | | |
676
+ | | | | | 01879--7884 | |
677
+ | | | | | 90210 | |
678
+ | | | | | | |
679
+ +========+========+============+===+=============+===+
680
+ #+end_example
597
681
 
598
682
  In addition, at any time after creating a table, you can force the String type
599
683
  on any number of columns with the ~force_string!~ method. When you do so, all
600
684
  exisiting items in the column are converted to strings with the #to_s method.
601
685
 
602
- #+begin_src ruby :wrap EXAMPLE
686
+ #+begin_src ruby
603
687
  tab = FatTable.new(:a, 'b', 'C', :d, :zip)
604
688
  tab << { a: 1, b: 2, c: "<2017-01-21>", d: 'f', e: '', zip: 18552 }
605
689
  tab << { a: 3.14, b: 2.17, c: '[2016-01-21 Thu]', d: 'Y', e: nil }
@@ -610,17 +694,18 @@ exisiting items in the column are converted to strings with the #to_s method.
610
694
  tab.to_text
611
695
  #+end_src
612
696
 
613
- #+begin_EXAMPLE
614
- +======+======+============+===+=======+===+
615
- | A | B | C | D | Zip | E |
616
- +------+------+------------+---+-------+---+
617
- | 1 | 2 | 2017-01-21 | F | 18552 | |
618
- | 3.14 | 2.17 | 2016-01-21 | T | | |
619
- | | | | | 01879 | |
620
- | | | | | 66210 | |
621
- | | | | | 90210 | |
622
- +======+======+============+===+=======+===+
623
- #+end_EXAMPLE
697
+ #+RESULTS:
698
+ #+begin_example
699
+ +========+========+============+===+=======+===+
700
+ | A | B | C | D | Zip | E |
701
+ +--------+--------+------------+---+-------+---+
702
+ | 1 | 2 | 2017-01-21 | F | 18552 | |
703
+ | 3.1400 | 2.1700 | 2016-01-21 | T | | |
704
+ | | | | | 01879 | |
705
+ | | | | | 66210 | |
706
+ | | | | | 90210 | |
707
+ +========+========+============+===+=======+===+
708
+ #+end_example
624
709
 
625
710
  *** From CSV or Org Mode files or strings
626
711
  Tables can also be read from ~.csv~ files or files containing ~org-mode~
@@ -633,11 +718,11 @@ followed by ~|-~. Only the first table in an ~.org~ file is read.
633
718
  For both ~.csv~ and ~.org~ files, the first row in the table is taken as the
634
719
  header row, and the headers are converted to symbols as described above.
635
720
 
636
- #+BEGIN_SRC ruby
637
- tab1 = FatTable.from_csv_file('~/data.csv')
638
- tab2 = FatTable.from_org_file('~/project.org')
721
+ #+BEGIN_SRC ruby :results silent
722
+ tab1 = FatTable.from_csv_file('~/data.csv')
723
+ tab2 = FatTable.from_org_file('~/project.org')
639
724
 
640
- csv_body = <<-EOS
725
+ csv_body = <<-EOS
641
726
  Ref,Date,Code,RawShares,Shares,Price,Info
642
727
  1,2006-05-02,P,5000,5000,8.6000,2006-08-09-1-I
643
728
  2,2006-05-03,P,5000,5000,8.4200,2006-08-09-1-I
@@ -647,15 +732,15 @@ header row, and the headers are converted to symbols as described above.
647
732
  6,2006-05-12,P,2000,2000,6.7400,2006-08-09-1-I
648
733
  EOS
649
734
 
650
- tab3 = FatTable.from_csv_string(csv_body)
735
+ tab3 = FatTable.from_csv_string(csv_body)
651
736
 
652
- org_body = <<-EOS
737
+ org_body = <<-EOS
653
738
  .* Smith Transactions
654
739
  :PROPERTIES:
655
740
  :TABLE_EXPORT_FILE: smith.csv
656
741
  :END:
657
742
 
658
- #+TBLNAME: smith_tab
743
+ ,#+TBLNAME: smith_tab
659
744
  | Ref | Date | Code | Raw | Shares | Price | Info |
660
745
  |-----+------------+------+---------+--------+----------+---------|
661
746
  | 29 | 2013-05-02 | P | 795,546 | 2,609 | 1.18500 | ENTITY1 |
@@ -676,7 +761,7 @@ header row, and the headers are converted to symbols as described above.
676
761
  .* Another Heading
677
762
  EOS
678
763
 
679
- tab4 = FatTable.from_org_string(org_body)
764
+ tab4 = FatTable.from_org_string(org_body)
680
765
  #+END_SRC
681
766
 
682
767
  *** From Arrays of Arrays
@@ -691,15 +776,15 @@ ending it with a '~'.
691
776
  aoa = [
692
777
  ['Ref', 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Bool'],
693
778
  [1, '2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'ENTITY1', 'T'],
694
- [2, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ENTITY1', 'T'],
779
+ [2, '2013-05-02', 'P', '118_186.40', 118_186.4, 11.8500, 'ENTITY1', 'T'],
695
780
  [7, '2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'ENTITY3', 'F'],
696
781
  [8, '2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'ENTITY3', 'T'],
697
782
  [9, '2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'ENTITY3', 'T'],
698
- [10, '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', 'T'],
783
+ [10, Date.parse('2013-05-23'), 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', true],
699
784
  [11, '2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'ENTITY3', 'F'],
700
- [12, '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ENTITY3', 'T'],
785
+ ['12', '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ENTITY3', 'T'],
701
786
  [13, '2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'ENTITY3', 'T'],
702
- [14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ENTITY3', 'F'],
787
+ [14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ENTITY3', false],
703
788
  [15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ENTITY3', 'T'],
704
789
  [16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ENTITY3', 'T'] ]
705
790
 
@@ -707,20 +792,22 @@ ending it with a '~'.
707
792
  #+END_SRC
708
793
 
709
794
  #+RESULTS:
710
- | Ref | Date | Code | Raw | Shares | Price | Info | Bool |
711
- |-----+------------+------+--------+--------+-------+---------+------|
712
- | 1 | 2013-05-02 | P | 795546 | 795546 | 1 | ENTITY1 | T |
713
- | 2 | 2013-05-02 | P | 118186 | 118186 | 12 | ENTITY1 | T |
714
- | 7 | 2013-05-20 | S | 12000 | 5046 | 28 | ENTITY3 | F |
715
- | 8 | 2013-05-20 | S | 85000 | 35743 | 28 | ENTITY3 | T |
716
- | 9 | 2013-05-20 | S | 33302 | 14003 | 29 | ENTITY3 | T |
717
- | 10 | 2013-05-23 | S | 8000 | 3364 | 27 | ENTITY3 | T |
718
- | 11 | 2013-05-23 | S | 23054 | 9694 | 27 | ENTITY3 | F |
719
- | 12 | 2013-05-23 | S | 39906 | 16780 | 25 | ENTITY3 | T |
720
- | 13 | 2013-05-29 | S | 13459 | 5660 | 25 | ENTITY3 | T |
721
- | 14 | 2013-05-29 | S | 15700 | 6602 | 25 | ENTITY3 | F |
722
- | 15 | 2013-05-29 | S | 15900 | 6686 | 25 | ENTITY3 | T |
723
- | 16 | 2013-05-30 | S | 6679 | 2809 | 25 | ENTITY3 | T |
795
+ #+begin_example
796
+ | Ref | Date | Code | Raw | Shares | Price | Info | Bool |
797
+ |-----+------------+------+-------------+-------------+---------+---------+------|
798
+ | 1 | 2013-05-02 | P | 795546.2000 | 795546.2000 | 1.1850 | ENTITY1 | T |
799
+ | 2 | 2013-05-02 | P | 118186.4000 | 118186.4000 | 11.8500 | ENTITY1 | T |
800
+ | 7 | 2013-05-20 | S | 12000.0000 | 5046.0000 | 28.2804 | ENTITY3 | F |
801
+ | 8 | 2013-05-20 | S | 85000.0000 | 35742.5000 | 28.3224 | ENTITY3 | T |
802
+ | 9 | 2013-05-20 | S | 33302.0000 | 14003.4900 | 28.6383 | ENTITY3 | T |
803
+ | 10 | 2013-05-23 | S | 8000.0000 | 3364.0000 | 27.1083 | ENTITY3 | T |
804
+ | 11 | 2013-05-23 | S | 23054.0000 | 9694.2100 | 26.8015 | ENTITY3 | F |
805
+ | 12 | 2013-05-23 | S | 39906.0000 | 16780.4700 | 25.1749 | ENTITY3 | T |
806
+ | 13 | 2013-05-29 | S | 13459.0000 | 5659.5100 | 24.7464 | ENTITY3 | T |
807
+ | 14 | 2013-05-29 | S | 15700.0000 | 6601.8500 | 24.7790 | ENTITY3 | F |
808
+ | 15 | 2013-05-29 | S | 15900.0000 | 6685.9500 | 24.5802 | ENTITY3 | T |
809
+ | 16 | 2013-05-30 | S | 6679.0000 | 2808.5200 | 25.0471 | ENTITY3 | T |
810
+ #+end_example
724
811
 
725
812
  Notice that the values can either be ruby objects, such as the Integer ~85_000~,
726
813
  or strings that can be parsed into one of the permissible column types.
@@ -806,7 +893,7 @@ to a Hash with the ~#to_h~ method, so you can use an array of your own objects
806
893
  to initialize a table, provided that you define a suitable ~#to_h~ method for
807
894
  the objects' class.
808
895
 
809
- #+BEGIN_SRC ruby :results silent
896
+ #+BEGIN_SRC ruby
810
897
  aoh = [
811
898
  { ref: 'T001', date: '2016-11-01', code: 'P', price: '7.7000', shares: 100 },
812
899
  { ref: 'T002', date: '2016-11-01', code: 'P', price: 7.7500, shares: 200 },
@@ -825,9 +912,31 @@ aoh = [
825
912
  { ref: 'T015', date: '2016-11-02', code: 'P', price: 7.7500, shares: 500 },
826
913
  { ref: 'T016', date: '2016-11-02', code: 'P', price: 8.2500, shares: 100 }
827
914
  ]
828
- tab = FatTable.from_aoh(aoh)
915
+ tab = FatTable.from_aoh(aoh).to_aoa
829
916
  #+END_SRC
830
917
 
918
+ #+RESULTS:
919
+ #+begin_example
920
+ | Ref | Date | Code | Price | Shares |
921
+ |------+------------+------+--------+--------|
922
+ | T001 | 2016-11-01 | P | 7.7000 | 100 |
923
+ | T002 | 2016-11-01 | P | 7.7500 | 200 |
924
+ | T003 | 2016-11-01 | P | 7.5000 | 800 |
925
+ | T004 | 2016-11-01 | S | 7.5500 | 6811 |
926
+ | T005 | 2026-11-23 | S | 7.5000 | 4000 |
927
+ | T006 | 2016-11-01 | S | 7.6000 | 1000 |
928
+ | T007 | 2016-11-01 | S | 7.6500 | 200 |
929
+ | T008 | 2016-11-01 | P | 7.6500 | 2771 |
930
+ | T009 | 2016-11-01 | P | 7.6000 | 9550 |
931
+ | T010 | 2016-11-01 | P | 7.5500 | 3175 |
932
+ | T011 | 2016-11-02 | P | 7.4250 | 100 |
933
+ | T012 | 2016-11-02 | P | 7.5500 | 4700 |
934
+ | T013 | 2016-11-02 | P | 7.3500 | 53100 |
935
+ | T014 | 2016-11-02 | P | 7.4500 | 5847 |
936
+ | T015 | 2016-11-02 | P | 7.7500 | 500 |
937
+ | T016 | 2016-11-02 | P | 8.2500 | 100 |
938
+ #+end_example
939
+
831
940
  Notice, again, that the values can either be ruby objects, such as ~Date.today~,
832
941
  or strings that can be parsed into one of the permissible column types.
833
942
 
@@ -842,41 +951,62 @@ you are accessing a Postgres database, you must install the ~pg~ gem with
842
951
  $ gem install pg
843
952
  #+end_src
844
953
 
845
- You must first set the database parameters to be used for the queries.
954
+ #+RESULTS:
955
+
956
+ You must first call ~FatTable.connect~ to set the database parameters to be
957
+ used for the queries.
958
+
959
+ The arguments to ~connect~ are simply passed on to ~sequel~'s connect method, so
960
+ any set of arguments that work for it should work for ~connect~. Alternatively,
961
+ you can build the ~Sequel~ connection directly with ~Sequel.connect~ or with
962
+ adapter-specific ~Sequel~ connection methods and let ~FatTable~ know to use that
963
+ connection:
846
964
 
847
965
  #+BEGIN_SRC ruby
848
966
  # This automatically requires sequel.
849
967
  FatTable.connect(adapter: 'sqlite',
850
- database: 'examples/trades.db')
968
+ database: 'spec/example_files/trades2.db')
851
969
  tab = FatTable.from_sql('select * from trans;').to_text
852
970
  #+END_SRC
853
971
 
972
+ #+RESULTS:
854
973
  #+begin_example
855
- +============+======+==========+==========+=========+=========+====+
856
- | Date | Code | Raw | Shares | Price | Info | Ok |
857
- +------------+------+----------+----------+---------+---------+----+
858
- | 2013-05-29 | S | 15700.0 | 6601.85 | 24.779 | ENTITY3 | F |
859
- | 2013-05-02 | P | 118186.4 | 118186.4 | 11.85 | ENTITY1 | T |
860
- | 2013-05-20 | S | 12000.0 | 5046.0 | 28.2804 | ENTITY3 | F |
861
- | 2013-05-23 | S | 8000.0 | 3364.0 | 27.1083 | ENTITY3 | T |
862
- | 2013-05-23 | S | 39906.0 | 16780.47 | 25.1749 | ENTITY3 | T |
863
- | 2013-05-20 | S | 85000.0 | 35742.5 | 28.3224 | ENTITY3 | T |
864
- | 2013-05-02 | P | 795546.2 | 795546.2 | 1.185 | ENTITY1 | T |
865
- | 2013-05-29 | S | 13459.0 | 5659.51 | 24.7464 | ENTITY3 | T |
866
- | 2013-05-20 | S | 33302.0 | 14003.49 | 28.6383 | ENTITY3 | T |
867
- | 2013-05-29 | S | 15900.0 | 6685.95 | 24.5802 | ENTITY3 | T |
868
- | 2013-05-30 | S | 6679.0 | 2808.52 | 25.0471 | ENTITY3 | T |
869
- | 2013-05-23 | S | 23054.0 | 9694.21 | 26.8015 | ENTITY3 | F |
870
- +============+======+==========+==========+=========+=========+====+
974
+ +============+======+=============+=============+=========+=========+====+
975
+ | Date | Code | Raw | Shares | Price | Info | Ok |
976
+ +------------+------+-------------+-------------+---------+---------+----+
977
+ | 2013-05-29 | S | 15700.0000 | 6601.8500 | 24.7790 | ENTITY3 | F |
978
+ | 2013-05-02 | P | 118186.4000 | 118186.4000 | 11.8500 | ENTITY1 | T |
979
+ | 2013-05-20 | S | 12000.0000 | 5046.0000 | 28.2804 | ENTITY3 | F |
980
+ | 2013-05-23 | S | 8000.0000 | 3364.0000 | 27.1083 | ENTITY3 | T |
981
+ | 2013-05-23 | S | 39906.0000 | 16780.4700 | 25.1749 | ENTITY3 | T |
982
+ | 2013-05-20 | S | 85000.0000 | 35742.5000 | 28.3224 | ENTITY3 | T |
983
+ | 2013-05-02 | P | 795546.2000 | 795546.2000 | 1.1850 | ENTITY1 | T |
984
+ | 2013-05-29 | S | 13459.0000 | 5659.5100 | 24.7464 | ENTITY3 | T |
985
+ | 2013-05-20 | S | 33302.0000 | 14003.4900 | 28.6383 | ENTITY3 | T |
986
+ | 2013-05-29 | S | 15900.0000 | 6685.9500 | 24.5802 | ENTITY3 | T |
987
+ | 2013-05-30 | S | 6679.0000 | 2808.5200 | 25.0471 | ENTITY3 | T |
988
+ | 2013-05-23 | S | 23054.0000 | 9694.2100 | 26.8015 | ENTITY3 | F |
989
+ +============+======+=============+=============+=========+=========+====+
871
990
  #+end_example
872
991
 
873
- The arguments to ~connect~ are simply passed on to ~sequel~'s connect method, so
874
- any set of arguments that work for it should work for ~connect~. Alternatively,
875
- you can build the ~Sequel~ connection directly with ~Sequel.connect~ or with
876
- adapter-specific ~Sequel~ connection methods and let ~FatTable~ know to use that
877
- connection:
992
+ The same connection can be queries multiple times:
878
993
 
879
994
  #+BEGIN_SRC ruby
995
+ tab = FatTable.from_sql('select * from trans where info = "ENTITY1";')
996
+ tab.to_text
997
+ #+END_SRC
998
+
999
+ #+RESULTS:
1000
+ #+begin_example
1001
+ +============+======+=============+=============+=========+=========+====+
1002
+ | Date | Code | Raw | Shares | Price | Info | Ok |
1003
+ +------------+------+-------------+-------------+---------+---------+----+
1004
+ | 2013-05-02 | P | 118186.4000 | 118186.4000 | 11.8500 | ENTITY1 | T |
1005
+ | 2013-05-02 | P | 795546.2000 | 795546.2000 | 1.1850 | ENTITY1 | T |
1006
+ +============+======+=============+=============+=========+=========+====+
1007
+ #+end_example
1008
+
1009
+ #+BEGIN_SRC ruby :eval no
880
1010
  FatTable.db = Sequel.connect('postgres://user:password@localhost/dbname')
881
1011
  FatTable.db = Sequel.ado(conn_string: 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=drive:\path\filename.accdb')
882
1012
  #+END_SRC
@@ -890,14 +1020,12 @@ called again.
890
1020
 
891
1021
  *** Marking Groups in Input
892
1022
  **** Manually
893
-
894
1023
  At any point, you can add a boundary to a table by invokong the
895
1024
  ~mark_boundary~ method. Without an argument, it adds the boundary to the end
896
1025
  of the table; with a numeric argument, ~n~, it adds the boundary after row
897
1026
  ~n~.
898
1027
 
899
1028
  **** When Reading in Tables
900
-
901
1029
  ~FatTable~ tables has a concept of "groups" of rows that play a role in many of
902
1030
  the methods for operating on them as explained [[Groups][below]].
903
1031
 
@@ -920,7 +1048,6 @@ beginning with something like ~|---~. The ~.from_org_...~ functions always
920
1048
  recognizes hlines in the input, so it takes no ~hlines:~ keyword parameter.
921
1049
 
922
1050
  ** Accessing Parts of Tables
923
-
924
1051
  *** Rows
925
1052
  A ~FatTable~ table is an Enumerable, yielding each row of the table as a Hash
926
1053
  keyed on the header symbols. The method ~Table#rows~ returns an Array of the
@@ -940,7 +1067,7 @@ all the items of the table's ~:ref~ column.
940
1067
  The two forms of indexing can be combined, in either order, to access
941
1068
  individual cells of the table:
942
1069
 
943
- #+BEGIN_SRC ruby
1070
+ #+BEGIN_SRC ruby :eval no
944
1071
  tab[13] # => Hash of the 14th row
945
1072
  tab[:date] # => Array of all Dates in the :date column
946
1073
  tab[13][:date] # => The Date in the 14th row
@@ -950,7 +1077,7 @@ individual cells of the table:
950
1077
  *** Other table attributes
951
1078
  Here is a quick rundown of other table attributes that you can access:
952
1079
 
953
- #+BEGIN_SRC ruby
1080
+ #+BEGIN_SRC ruby :eval no
954
1081
  tab.headers # => an Array of the headers in symbol form
955
1082
  tab.types # => a Hash mapping headers to column types
956
1083
  tab.type(head) # => return the type of the column for the given head
@@ -964,26 +1091,28 @@ Here is a quick rundown of other table attributes that you can access:
964
1091
 
965
1092
  You should note that what the ~.types~ and ~.type(head)~ methods return is a
966
1093
  string naming the "type" assigned by ~FatTable~. All of them are also the
967
- names of Ruby classes except to 'Boolean' a class that doesn't exist in Ruby.
1094
+ names of Ruby classes except for 'Boolean' a class that doesn't exist in Ruby.
968
1095
  The value ~true~ is a member of the ~TrueClass~ and ~false~ a member of the
969
1096
  ~FalseClass~. So for ~FatTable~ to provide a column of type 'Boolean'
970
1097
  requires it to synthesize the type from these Ruby classes.
971
1098
 
972
- #+begin_src ruby :wrap EXAMPLE :results raw
1099
+ #+begin_src ruby :results raw
973
1100
  tab.types
974
1101
  #+end_src
975
1102
 
976
- #+begin_EXAMPLE
977
- {:a=>"Numeric", :b=>"Numeric", :c=>"DateTime", :d=>"Boolean", :e=>"NilClass", :f=>"Numeric"}
978
- #+end_EXAMPLE
1103
+ #+RESULTS:
1104
+ #+begin_example
1105
+ {date: "DateTime", code: "String", raw: "Numeric", shares: "Numeric", price: "Numeric", info: "String", ok: "Boolean"}
1106
+ #+end_example
979
1107
 
980
- #+begin_src ruby :wrap EXAMPLE :results output
981
- puts "Column :d says its type is '#{tab.type(:d)}' and that is a #{tab.type(:d).class}"
1108
+ #+begin_src ruby :results output
1109
+ puts "Column :shares says its type is '#{tab.type(:shares)}' and that is a #{tab[:shares][0].class}"
982
1110
  #+end_src
983
1111
 
984
- #+begin_EXAMPLE
985
- Column :d says its type is 'Boolean' and that is a String
986
- #+end_EXAMPLE
1112
+ #+RESULTS:
1113
+ #+begin_example
1114
+ Column :shares says its type is 'Numeric' and that is a BigDecimal
1115
+ #+end_example
987
1116
 
988
1117
  ** Operations on Tables
989
1118
  Once you have one or more tables, you will likely want to perform operations on
@@ -991,12 +1120,12 @@ them. The operations provided by ~FatTable~ are the subject of this section.
991
1120
  Before getting into the operations, though, there are a couple of issues that
992
1121
  cut across all or many of the operations.
993
1122
 
994
- First, tables are by and large immutable objects. Each operation creates a new
995
- table without affecting the input tables. The only exceptions are the
996
- ~degroup!~ operation, which mutates the receiver table by removing its group
997
- boundaries, and ~force_string!~ (explained above at [[*Forcing String Type][Forcing String Type]]),
998
- which forces columns to have the String type despite what the automatic typing
999
- 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.
1000
1129
 
1001
1130
  Second, because each operation returns a ~FatTable::Table~ object, the
1002
1131
  operations are chainable.
@@ -1007,9 +1136,9 @@ operations result in marking group boundaries in the result table, others
1007
1136
  remove group boundaries that may have existed in the input table. Operations
1008
1137
  that either create or remove groups will be noted below.
1009
1138
 
1010
- Finally, the operations are for the most part patterned on SQL table operations,
1011
- but when expressions play a role, you write them using ruby syntax rather than
1012
- 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.
1013
1142
 
1014
1143
  *** Example Input Tables
1015
1144
  For illustration purposes assume that the following tables are read into ruby
@@ -1070,58 +1199,113 @@ EOS
1070
1199
  #+END_SRC
1071
1200
 
1072
1201
  Rendering ~tab1~ into Emacs org-mode:
1073
- #+BEGIN_SRC ruby :wrap EXAMPLE :results silent
1202
+ #+BEGIN_SRC ruby
1074
1203
  tab1 = FatTable.from_org_string(tab1_str)
1204
+ tab1.to_aoa
1075
1205
  #+END_SRC
1076
1206
 
1207
+ #+RESULTS:
1208
+ #+begin_example
1209
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1210
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1211
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1212
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1213
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1214
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1215
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1216
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
1217
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
1218
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1219
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1220
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1221
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
1222
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
1223
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1224
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1225
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1226
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1227
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1228
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1229
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1230
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1231
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1232
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1233
+ #+end_example
1234
+
1235
+
1077
1236
  Rendering ~tab2~ into Emacs org-mode:
1078
1237
 
1079
- #+BEGIN_SRC ruby :wrap EXAMPLE :results silent
1238
+ #+BEGIN_SRC ruby
1080
1239
  tab2 = FatTable.from_org_string(tab2_str)
1240
+ tab2.to_aoa
1081
1241
  #+END_SRC
1082
1242
 
1243
+ #+RESULTS:
1244
+ #+begin_example
1245
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1246
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
1247
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1248
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1249
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
1250
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
1251
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
1252
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
1253
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1254
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1255
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
1256
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1257
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1258
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1259
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1260
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
1261
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
1262
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
1263
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
1264
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
1265
+ #+end_example
1266
+
1083
1267
  *** Select
1084
1268
  With the ~select~ method, you can select columns to appear in the output
1085
1269
  table, rearrange their order, and create new columns that are a function of
1086
1270
  other columns.
1087
1271
 
1088
1272
  **** Selecting Existing Columns (Also of :omni)
1089
-
1090
1273
  Here we select three existing columns by simply passing header symbols in the
1091
1274
  order we want them to appear in the output. Thus, one use of =select= is to
1092
1275
  filter and permute the order of existing columns. The =select= method preserves
1093
1276
  any group boundaries present in the input table.
1094
1277
 
1095
- #+BEGIN_SRC ruby :wrap EXAMPLE
1278
+ #+BEGIN_SRC ruby
1096
1279
  tab1.select(:price, :ref, :shares).to_aoa
1097
1280
  #+END_SRC
1098
1281
 
1099
- #+BEGIN_EXAMPLE
1100
- | Price | Ref | Shares |
1101
- |-------+------+--------|
1102
- | 7.7 | T001 | 100 |
1103
- | 7.75 | T002 | 200 |
1104
- | 7.5 | T003 | 800 |
1105
- | 7.5 | T003 | 800 |
1106
- |-------+------+--------|
1107
- | 7.55 | T004 | 6811 |
1108
- | 7.5 | T005 | 4000 |
1109
- | 7.6 | T006 | 1000 |
1110
- | 7.6 | T006 | 1000 |
1111
- | 7.65 | T007 | 200 |
1112
- | 7.65 | T008 | 2771 |
1113
- | 7.6 | T009 | 9550 |
1114
- |-------+------+--------|
1115
- | 7.55 | T010 | 3175 |
1116
- | 7.425 | T011 | 100 |
1117
- | 7.55 | T012 | 4700 |
1118
- | 7.55 | T012 | 4700 |
1119
- | 7.35 | T013 | 53100 |
1120
- |-------+------+--------|
1121
- | 7.45 | T014 | 5847 |
1122
- | 7.75 | T015 | 500 |
1123
- | 8.25 | T016 | 100 |
1124
- #+END_EXAMPLE
1282
+ #+RESULTS:
1283
+ #+begin_example
1284
+ | Price | Ref | Shares |
1285
+ |--------+------+--------|
1286
+ | 7.7000 | T001 | 100 |
1287
+ | 7.7500 | T002 | 200 |
1288
+ | 7.5000 | T003 | 800 |
1289
+ | 7.5000 | T003 | 800 |
1290
+ |--------+------+--------|
1291
+ | 7.5500 | T004 | 6811 |
1292
+ | 7.5000 | T005 | 4000 |
1293
+ | 7.6000 | T006 | 1000 |
1294
+ | 7.6000 | T006 | 1000 |
1295
+ | 7.6500 | T007 | 200 |
1296
+ | 7.6500 | T008 | 2771 |
1297
+ | 7.6000 | T009 | 9550 |
1298
+ |--------+------+--------|
1299
+ | 7.5500 | T010 | 3175 |
1300
+ | 7.4250 | T011 | 100 |
1301
+ | 7.5500 | T012 | 4700 |
1302
+ | 7.5500 | T012 | 4700 |
1303
+ | 7.3500 | T013 | 53100 |
1304
+ |--------+------+--------|
1305
+ | 7.4500 | T014 | 5847 |
1306
+ | 7.7500 | T015 | 500 |
1307
+ | 8.2500 | T016 | 100 |
1308
+ #+end_example
1125
1309
 
1126
1310
  It can be tedious to type the names of all the columns in a ~select~
1127
1311
  statement, so ~FatTable~ recognizes the special column name ~:omni~. If the
@@ -1132,79 +1316,79 @@ non-existent column unless you happen to have a column named ~:omni~ in your
1132
1316
  table, which is not advisable. You can add hash arguments after ~:omni~ but
1133
1317
  you cannot add additional column names:
1134
1318
 
1135
- #+BEGIN_SRC ruby :wrap EXAMPLE
1319
+ #+BEGIN_SRC ruby
1136
1320
  tab1.select(:omni, cost: 'shares * price').to_aoa
1137
1321
  #+END_SRC
1138
1322
 
1139
- #+begin_EXAMPLE
1140
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp | Cost |
1141
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1142
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 770.0 |
1143
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1550.0 |
1144
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0 |
1145
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0 |
1146
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1147
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 | 51423.05 |
1148
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 | 30000.0 |
1149
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0 |
1150
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0 |
1151
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1530.0 |
1152
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 | 21198.15 |
1153
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 | 72580.0 |
1154
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1155
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 | 23971.25 |
1156
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 742.5 |
1157
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0 |
1158
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0 |
1159
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 | 390285.0 |
1160
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1161
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 | 43560.15 |
1162
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 | 3875.0 |
1163
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 | 825.0 |
1164
- #+end_EXAMPLE
1323
+ #+RESULTS:
1324
+ #+begin_example
1325
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp | Cost |
1326
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1327
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 770.0000 |
1328
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1550.0000 |
1329
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0000 |
1330
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0000 |
1331
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1332
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 | 51423.0500 |
1333
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 | 30000.0000 |
1334
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0000 |
1335
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0000 |
1336
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1530.0000 |
1337
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 | 21198.1500 |
1338
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 | 72580.0000 |
1339
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1340
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 | 23971.2500 |
1341
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 742.5000 |
1342
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0000 |
1343
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0000 |
1344
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 | 390285.0000 |
1345
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1346
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 | 43560.1500 |
1347
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 | 3875.0000 |
1348
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 | 825.0000 |
1349
+ #+end_example
1165
1350
 
1166
1351
  **** Copying and Renaming Existing Columns.
1167
-
1168
1352
  After the list of selected column names in the call to ~select~, you can add
1169
1353
  any number of hash-like arguments. You can use these to add a copy of an
1170
1354
  existing column. By calling select again, you can include only the copied
1171
1355
  column, in effect renaming it. For example, if you want ~tab1~ but with ~:ref~
1172
1356
  changed to ~:id~, just add an argument to define the new ~:id~ column:
1173
1357
 
1174
- #+BEGIN_SRC ruby :wrap EXAMPLE
1358
+ #+BEGIN_SRC ruby
1175
1359
  tab1.select(:omni, id: :ref).
1176
1360
  select(:id, :date, :code, :price, :shares).to_aoa
1177
1361
  #+END_SRC
1178
1362
 
1179
- #+begin_EXAMPLE
1180
- | Id | Date | Code | Price | Shares |
1181
- |------+------------+------+-------+--------|
1182
- | T001 | 2016-11-01 | P | 7.7 | 100 |
1183
- | T002 | 2016-11-01 | P | 7.75 | 200 |
1184
- | T003 | 2016-11-01 | P | 7.5 | 800 |
1185
- | T003 | 2016-11-01 | P | 7.5 | 800 |
1186
- |------+------------+------+-------+--------|
1187
- | T004 | 2016-11-01 | S | 7.55 | 6811 |
1188
- | T005 | 2016-11-01 | S | 7.5 | 4000 |
1189
- | T006 | 2016-11-01 | S | 7.6 | 1000 |
1190
- | T006 | 2016-11-01 | S | 7.6 | 1000 |
1191
- | T007 | 2016-11-01 | S | 7.65 | 200 |
1192
- | T008 | 2016-11-01 | P | 7.65 | 2771 |
1193
- | T009 | 2016-11-01 | P | 7.6 | 9550 |
1194
- |------+------------+------+-------+--------|
1195
- | T010 | 2016-11-01 | P | 7.55 | 3175 |
1196
- | T011 | 2016-11-02 | P | 7.425 | 100 |
1197
- | T012 | 2016-11-02 | P | 7.55 | 4700 |
1198
- | T012 | 2016-11-02 | P | 7.55 | 4700 |
1199
- | T013 | 2016-11-02 | P | 7.35 | 53100 |
1200
- |------+------------+------+-------+--------|
1201
- | T014 | 2016-11-02 | P | 7.45 | 5847 |
1202
- | T015 | 2016-11-02 | P | 7.75 | 500 |
1203
- | T016 | 2016-11-02 | P | 8.25 | 100 |
1204
- #+end_EXAMPLE
1205
-
1206
- **** Adding New Columns
1363
+ #+RESULTS:
1364
+ #+begin_example
1365
+ | Id | Date | Code | Price | Shares |
1366
+ |------+------------+------+--------+--------|
1367
+ | T001 | 2016-11-01 | P | 7.7000 | 100 |
1368
+ | T002 | 2016-11-01 | P | 7.7500 | 200 |
1369
+ | T003 | 2016-11-01 | P | 7.5000 | 800 |
1370
+ | T003 | 2016-11-01 | P | 7.5000 | 800 |
1371
+ |------+------------+------+--------+--------|
1372
+ | T004 | 2016-11-01 | S | 7.5500 | 6811 |
1373
+ | T005 | 2016-11-01 | S | 7.5000 | 4000 |
1374
+ | T006 | 2016-11-01 | S | 7.6000 | 1000 |
1375
+ | T006 | 2016-11-01 | S | 7.6000 | 1000 |
1376
+ | T007 | 2016-11-01 | S | 7.6500 | 200 |
1377
+ | T008 | 2016-11-01 | P | 7.6500 | 2771 |
1378
+ | T009 | 2016-11-01 | P | 7.6000 | 9550 |
1379
+ |------+------------+------+--------+--------|
1380
+ | T010 | 2016-11-01 | P | 7.5500 | 3175 |
1381
+ | T011 | 2016-11-02 | P | 7.4250 | 100 |
1382
+ | T012 | 2016-11-02 | P | 7.5500 | 4700 |
1383
+ | T012 | 2016-11-02 | P | 7.5500 | 4700 |
1384
+ | T013 | 2016-11-02 | P | 7.3500 | 53100 |
1385
+ |------+------------+------+--------+--------|
1386
+ | T014 | 2016-11-02 | P | 7.4500 | 5847 |
1387
+ | T015 | 2016-11-02 | P | 7.7500 | 500 |
1388
+ | T016 | 2016-11-02 | P | 8.2500 | 100 |
1389
+ #+end_example
1207
1390
 
1391
+ **** Adding New Computed Columns
1208
1392
  More interesting is that ~select~ can take hash-like keyword arguments after
1209
1393
  the symbol arguments to create new columns in the output as functions of other
1210
1394
  columns. For each hash-like parameter, the keyword given must be a symbol,
@@ -1224,104 +1408,160 @@ variables are set the number of the current row and group number respectively.
1224
1408
  For example, if we want to rename the ~traded_on~ column to ~:date~ and add a
1225
1409
  new column to compute the cost of shares, we could do the following:
1226
1410
 
1227
- #+BEGIN_SRC ruby :wrap EXAMPLE
1411
+ #+BEGIN_SRC ruby
1228
1412
  tab1.select(:ref, :price, :shares, traded_on: :date, cost: 'price * shares').to_aoa
1229
1413
  #+END_SRC
1230
1414
 
1231
- #+BEGIN_EXAMPLE
1232
- | Ref | Price | Shares | Traded On | Cost |
1233
- |------+-------+--------+------------+----------|
1234
- | T001 | 7.7 | 100 | 2016-11-01 | 770.0 |
1235
- | T002 | 7.75 | 200 | 2016-11-01 | 1550.0 |
1236
- | T003 | 7.5 | 800 | 2016-11-01 | 6000.0 |
1237
- | T003 | 7.5 | 800 | 2016-11-01 | 6000.0 |
1238
- |------+-------+--------+------------+----------|
1239
- | T004 | 7.55 | 6811 | 2016-11-01 | 51423.05 |
1240
- | T005 | 7.5 | 4000 | 2016-11-01 | 30000.0 |
1241
- | T006 | 7.6 | 1000 | 2016-11-01 | 7600.0 |
1242
- | T006 | 7.6 | 1000 | 2016-11-01 | 7600.0 |
1243
- | T007 | 7.65 | 200 | 2016-11-01 | 1530.0 |
1244
- | T008 | 7.65 | 2771 | 2016-11-01 | 21198.15 |
1245
- | T009 | 7.6 | 9550 | 2016-11-01 | 72580.0 |
1246
- |------+-------+--------+------------+----------|
1247
- | T010 | 7.55 | 3175 | 2016-11-01 | 23971.25 |
1248
- | T011 | 7.425 | 100 | 2016-11-02 | 742.5 |
1249
- | T012 | 7.55 | 4700 | 2016-11-02 | 35485.0 |
1250
- | T012 | 7.55 | 4700 | 2016-11-02 | 35485.0 |
1251
- | T013 | 7.35 | 53100 | 2016-11-02 | 390285.0 |
1252
- |------+-------+--------+------------+----------|
1253
- | T014 | 7.45 | 5847 | 2016-11-02 | 43560.15 |
1254
- | T015 | 7.75 | 500 | 2016-11-02 | 3875.0 |
1255
- | T016 | 8.25 | 100 | 2016-11-02 | 825.0 |
1256
- #+END_EXAMPLE
1415
+ #+RESULTS:
1416
+ #+begin_example
1417
+ | Ref | Price | Shares | Traded On | Cost |
1418
+ |------+--------+--------+------------+-------------|
1419
+ | T001 | 7.7000 | 100 | 2016-11-01 | 770.0000 |
1420
+ | T002 | 7.7500 | 200 | 2016-11-01 | 1550.0000 |
1421
+ | T003 | 7.5000 | 800 | 2016-11-01 | 6000.0000 |
1422
+ | T003 | 7.5000 | 800 | 2016-11-01 | 6000.0000 |
1423
+ |------+--------+--------+------------+-------------|
1424
+ | T004 | 7.5500 | 6811 | 2016-11-01 | 51423.0500 |
1425
+ | T005 | 7.5000 | 4000 | 2016-11-01 | 30000.0000 |
1426
+ | T006 | 7.6000 | 1000 | 2016-11-01 | 7600.0000 |
1427
+ | T006 | 7.6000 | 1000 | 2016-11-01 | 7600.0000 |
1428
+ | T007 | 7.6500 | 200 | 2016-11-01 | 1530.0000 |
1429
+ | T008 | 7.6500 | 2771 | 2016-11-01 | 21198.1500 |
1430
+ | T009 | 7.6000 | 9550 | 2016-11-01 | 72580.0000 |
1431
+ |------+--------+--------+------------+-------------|
1432
+ | T010 | 7.5500 | 3175 | 2016-11-01 | 23971.2500 |
1433
+ | T011 | 7.4250 | 100 | 2016-11-02 | 742.5000 |
1434
+ | T012 | 7.5500 | 4700 | 2016-11-02 | 35485.0000 |
1435
+ | T012 | 7.5500 | 4700 | 2016-11-02 | 35485.0000 |
1436
+ | T013 | 7.3500 | 53100 | 2016-11-02 | 390285.0000 |
1437
+ |------+--------+--------+------------+-------------|
1438
+ | T014 | 7.4500 | 5847 | 2016-11-02 | 43560.1500 |
1439
+ | T015 | 7.7500 | 500 | 2016-11-02 | 3875.0000 |
1440
+ | T016 | 8.2500 | 100 | 2016-11-02 | 825.0000 |
1441
+ #+end_example
1257
1442
 
1258
1443
  The parameter ~traded_on: :date~ caused the ~:date~ column of the input table
1259
1444
  to be renamed ~:traded_on~, and the parameter ~cost: 'price * shares'~ created
1260
- a new column, ~:cost~, as the product of values in the ~:price~ and ~:shares~
1261
- columns.
1445
+ a new computed column, ~:cost~, as the product of values in the ~:price~ and
1446
+ ~:shares~ columns.
1262
1447
 
1263
1448
  The order of the columns in the result tables is the same as the order of the
1264
1449
  parameters to the ~select~ method. So, you can re-order the columns with a
1265
1450
  second, chained call to ~select~:
1266
1451
 
1267
- #+BEGIN_SRC ruby :wrap EXAMPLE
1452
+ #+BEGIN_SRC ruby
1268
1453
  tab1.select(:ref, :price, :shares, traded_on: :date, cost: 'price * shares').
1269
1454
  select(:ref, :traded_on, :price, :shares, :cost).to_aoa
1270
1455
  #+END_SRC
1271
1456
 
1272
- #+begin_EXAMPLE
1273
- | Ref | Traded On | Price | Shares | Cost |
1274
- |------+------------+-------+--------+----------|
1275
- | T001 | 2016-11-01 | 7.7 | 100 | 770.0 |
1276
- | T002 | 2016-11-01 | 7.75 | 200 | 1550.0 |
1277
- | T003 | 2016-11-01 | 7.5 | 800 | 6000.0 |
1278
- | T003 | 2016-11-01 | 7.5 | 800 | 6000.0 |
1279
- |------+------------+-------+--------+----------|
1280
- | T004 | 2016-11-01 | 7.55 | 6811 | 51423.05 |
1281
- | T005 | 2016-11-01 | 7.5 | 4000 | 30000.0 |
1282
- | T006 | 2016-11-01 | 7.6 | 1000 | 7600.0 |
1283
- | T006 | 2016-11-01 | 7.6 | 1000 | 7600.0 |
1284
- | T007 | 2016-11-01 | 7.65 | 200 | 1530.0 |
1285
- | T008 | 2016-11-01 | 7.65 | 2771 | 21198.15 |
1286
- | T009 | 2016-11-01 | 7.6 | 9550 | 72580.0 |
1287
- |------+------------+-------+--------+----------|
1288
- | T010 | 2016-11-01 | 7.55 | 3175 | 23971.25 |
1289
- | T011 | 2016-11-02 | 7.425 | 100 | 742.5 |
1290
- | T012 | 2016-11-02 | 7.55 | 4700 | 35485.0 |
1291
- | T012 | 2016-11-02 | 7.55 | 4700 | 35485.0 |
1292
- | T013 | 2016-11-02 | 7.35 | 53100 | 390285.0 |
1293
- |------+------------+-------+--------+----------|
1294
- | T014 | 2016-11-02 | 7.45 | 5847 | 43560.15 |
1295
- | T015 | 2016-11-02 | 7.75 | 500 | 3875.0 |
1296
- | T016 | 2016-11-02 | 8.25 | 100 | 825.0 |
1297
- #+end_EXAMPLE
1457
+ #+RESULTS:
1458
+ #+begin_example
1459
+ | Ref | Traded On | Price | Shares | Cost |
1460
+ |------+------------+--------+--------+-------------|
1461
+ | T001 | 2016-11-01 | 7.7000 | 100 | 770.0000 |
1462
+ | T002 | 2016-11-01 | 7.7500 | 200 | 1550.0000 |
1463
+ | T003 | 2016-11-01 | 7.5000 | 800 | 6000.0000 |
1464
+ | T003 | 2016-11-01 | 7.5000 | 800 | 6000.0000 |
1465
+ |------+------------+--------+--------+-------------|
1466
+ | T004 | 2016-11-01 | 7.5500 | 6811 | 51423.0500 |
1467
+ | T005 | 2016-11-01 | 7.5000 | 4000 | 30000.0000 |
1468
+ | T006 | 2016-11-01 | 7.6000 | 1000 | 7600.0000 |
1469
+ | T006 | 2016-11-01 | 7.6000 | 1000 | 7600.0000 |
1470
+ | T007 | 2016-11-01 | 7.6500 | 200 | 1530.0000 |
1471
+ | T008 | 2016-11-01 | 7.6500 | 2771 | 21198.1500 |
1472
+ | T009 | 2016-11-01 | 7.6000 | 9550 | 72580.0000 |
1473
+ |------+------------+--------+--------+-------------|
1474
+ | T010 | 2016-11-01 | 7.5500 | 3175 | 23971.2500 |
1475
+ | T011 | 2016-11-02 | 7.4250 | 100 | 742.5000 |
1476
+ | T012 | 2016-11-02 | 7.5500 | 4700 | 35485.0000 |
1477
+ | T012 | 2016-11-02 | 7.5500 | 4700 | 35485.0000 |
1478
+ | T013 | 2016-11-02 | 7.3500 | 53100 | 390285.0000 |
1479
+ |------+------------+--------+--------+-------------|
1480
+ | T014 | 2016-11-02 | 7.4500 | 5847 | 43560.1500 |
1481
+ | T015 | 2016-11-02 | 7.7500 | 500 | 3875.0000 |
1482
+ | T016 | 2016-11-02 | 8.2500 | 100 | 825.0000 |
1483
+ #+end_example
1298
1484
 
1299
1485
  **** Adding Constant Strings and Other Types in select
1300
-
1301
1486
  Because ~select~'s hash-like parameters evaluate a string as a ruby
1302
1487
  expression, as just described, it must provide a way to set a new column to a
1303
1488
  string literal. To indicate that a string should be inserted literally, add a
1304
1489
  ~:~ as the first non-blank character in the string. This will supress
1305
1490
  evaluation and insert the remainder of the string in the named column.
1306
1491
 
1307
- #+BEGIN_SRC ruby :wrap EXAMPLE
1492
+ #+BEGIN_SRC ruby
1308
1493
  tab1.select(:ref, :price, :shares, traded_on: :date, cost: ':the price of freedom').
1309
1494
  select(:ref, :traded_on, :price, :shares, :cost).to_aoa
1310
1495
  #+END_SRC
1311
1496
 
1497
+ #+RESULTS:
1498
+ #+begin_example
1499
+ | Ref | Traded On | Price | Shares | Cost |
1500
+ |------+------------+--------+--------+----------------------|
1501
+ | T001 | 2016-11-01 | 7.7000 | 100 | the price of freedom |
1502
+ | T002 | 2016-11-01 | 7.7500 | 200 | the price of freedom |
1503
+ | T003 | 2016-11-01 | 7.5000 | 800 | the price of freedom |
1504
+ | T003 | 2016-11-01 | 7.5000 | 800 | the price of freedom |
1505
+ |------+------------+--------+--------+----------------------|
1506
+ | T004 | 2016-11-01 | 7.5500 | 6811 | the price of freedom |
1507
+ | T005 | 2016-11-01 | 7.5000 | 4000 | the price of freedom |
1508
+ | T006 | 2016-11-01 | 7.6000 | 1000 | the price of freedom |
1509
+ | T006 | 2016-11-01 | 7.6000 | 1000 | the price of freedom |
1510
+ | T007 | 2016-11-01 | 7.6500 | 200 | the price of freedom |
1511
+ | T008 | 2016-11-01 | 7.6500 | 2771 | the price of freedom |
1512
+ | T009 | 2016-11-01 | 7.6000 | 9550 | the price of freedom |
1513
+ |------+------------+--------+--------+----------------------|
1514
+ | T010 | 2016-11-01 | 7.5500 | 3175 | the price of freedom |
1515
+ | T011 | 2016-11-02 | 7.4250 | 100 | the price of freedom |
1516
+ | T012 | 2016-11-02 | 7.5500 | 4700 | the price of freedom |
1517
+ | T012 | 2016-11-02 | 7.5500 | 4700 | the price of freedom |
1518
+ | T013 | 2016-11-02 | 7.3500 | 53100 | the price of freedom |
1519
+ |------+------------+--------+--------+----------------------|
1520
+ | T014 | 2016-11-02 | 7.4500 | 5847 | the price of freedom |
1521
+ | T015 | 2016-11-02 | 7.7500 | 500 | the price of freedom |
1522
+ | T016 | 2016-11-02 | 8.2500 | 100 | the price of freedom |
1523
+ #+end_example
1524
+
1312
1525
  This sets the ~:cost~ column to the string constant 'the price of freedom' for
1313
1526
  the whole table.
1314
1527
 
1315
1528
  You can set a column to a constant of any of the acceptable types, ~Numeric~,
1316
1529
  ~Date~, ~DateTime~, true, false, or nil.
1317
1530
 
1318
- #+BEGIN_SRC ruby :wrap EXAMPLE
1531
+ #+BEGIN_SRC ruby
1319
1532
  tab1.select(:ref, :price, :shares, traded_on: :date, cost: Math::PI, today: Date.today).
1320
1533
  select(:ref, :traded_on, :price, :shares, :cost, :today).to_aoa
1321
1534
  #+END_SRC
1322
1535
 
1323
- **** Custom Instance Variables and Hooks
1536
+ #+RESULTS:
1537
+ #+begin_example
1538
+ | Ref | Traded On | Price | Shares | Cost | Today |
1539
+ |------+------------+--------+--------+--------+------------|
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 |
1544
+ |------+------------+--------+--------+--------+------------|
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 |
1552
+ |------+------------+--------+--------+--------+------------|
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 |
1558
+ |------+------------+--------+--------+--------+------------|
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 |
1562
+ #+end_example
1324
1563
 
1564
+ **** Custom Instance Variables and Hooks
1325
1565
  As the above examples demonstrate, the instance variables ~@row~ and ~@group~
1326
1566
  are available when evaluating expressions that add new columns. You can also set
1327
1567
  up your own instance variables as well for keeping track of things that cross
@@ -1342,18 +1582,19 @@ shows the cumulative cost after each transaction in our example table. The
1342
1582
  following example uses the ~ivars:~ and ~before_hook:~ parameters to keep track
1343
1583
  of the running cost of shares, then formats the table.
1344
1584
 
1345
- #+BEGIN_SRC ruby :wrap EXAMPLE
1346
- tab = tab1.select(:ref, :price, :shares, traded_on: :date, \
1347
- cost: 'price * shares', cumulative: '@total_cost', \
1348
- ivars: { total_cost: 0 }, \
1585
+ #+BEGIN_SRC ruby
1586
+ tab = tab1.select(:ref, :price, :shares, traded_on: :date,
1587
+ cost: 'price * shares', cumulative: '@total_cost',
1588
+ ivars: { total_cost: 0 },
1349
1589
  before_hook: '@total_cost += price * shares')
1350
1590
  FatTable.to_aoa(tab) do |f|
1351
1591
  f.format(price: '0.4', shares: '0.0,', cost: '0.2,', cumulative: '0.2,')
1352
1592
  end
1353
1593
  #+END_SRC
1354
1594
 
1355
- #+BEGIN_EXAMPLE
1356
- | Ref | Price | Shares | Traded On | Cost | Cumulative |
1595
+ #+RESULTS:
1596
+ #+begin_example
1597
+ | Ref | Price | Shares | Traded On | Cost | Cumulative |
1357
1598
  |------+--------+--------+------------+------------+------------|
1358
1599
  | T001 | 7.7000 | 100 | 2016-11-01 | 770.00 | 770.00 |
1359
1600
  | T002 | 7.7500 | 200 | 2016-11-01 | 1,550.00 | 2,320.00 |
@@ -1377,10 +1618,9 @@ of the running cost of shares, then formats the table.
1377
1618
  | T014 | 7.4500 | 5,847 | 2016-11-02 | 43,560.15 | 735,780.10 |
1378
1619
  | T015 | 7.7500 | 500 | 2016-11-02 | 3,875.00 | 739,655.10 |
1379
1620
  | T016 | 8.2500 | 100 | 2016-11-02 | 825.00 | 740,480.10 |
1380
- #+END_EXAMPLE
1621
+ #+end_example
1381
1622
 
1382
1623
  **** Argument Order and Boundaries
1383
-
1384
1624
  Notice that ~select~ can take any number of arguments but all the symbol
1385
1625
  arguments must come first followed by all the hash-like keyword arguments,
1386
1626
  including the special arguments for instance variables and hooks.
@@ -1403,20 +1643,22 @@ table has only a single group.
1403
1643
  Here we select only those even-numbered rows where either of the two boolean
1404
1644
  fields is true:
1405
1645
 
1406
- #+BEGIN_SRC ruby :wrap EXAMPLE
1407
- tab1.where('@row.even? && (g10 || qp10)') \
1408
- .to_aoa
1646
+ #+BEGIN_SRC ruby
1647
+ tab1.where('@row.even? && (g10 || qp10)').to_term
1409
1648
  #+END_SRC
1410
1649
 
1411
- #+BEGIN_EXAMPLE
1412
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1413
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1414
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1415
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1416
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1417
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1418
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1419
- #+END_EXAMPLE
1650
+ #+RESULTS:
1651
+ #+begin_example
1652
+ ╒══════╤════════════╤══════╤════════╤═════╤══════╤════════╤══════╤═══════╤════════╤════════╕
1653
+ │ Ref │ Date │ Code │ Price │ G10 │ QP10 │ Shares │ Lp │ Qp │ Iplp │ Ipqp │
1654
+ ├──────┼────────────┼──────┼────────┼─────┼──────┼────────┼──────┼───────┼────────┼────────┤
1655
+ │ T002 │ 2016-11-01 │ P │ 7.7500 │ T │ F │ 200 │ 28 │ 172 │ 0.2453 │ 0.1924 │
1656
+ │ T003 │ 2016-11-01 │ P │ 7.5000 │ F │ T │ 800 │ 112 │ 688 │ 0.2453 │ 0.1924 │
1657
+ │ T006 │ 2016-11-01 │ S │ 7.6000 │ F │ T │ 1000 │ 143 │ 857 │ 0.2453 │ 0.1924 │
1658
+ │ T010 │ 2016-11-01 │ P │ 7.5500 │ F │ T │ 3175 │ 451 │ 2724 │ 0.2453 │ 0.1924 │
1659
+ │ T013 │ 2016-11-02 │ P │ 7.3500 │ T │ T │ 53100 │ 7656 │ 45444 │ 0.2453 │ 0.1924 │
1660
+ ╘══════╧════════════╧══════╧════════╧═════╧══════╧════════╧══════╧═══════╧════════╧════════╛
1661
+ #+end_example
1420
1662
 
1421
1663
  *** Order_by
1422
1664
  You can sort a table on any number of columns with ~order_by~. The ~order_by~
@@ -1429,42 +1671,45 @@ All columns of the input table are included in the output.
1429
1671
 
1430
1672
  Let's sort our table first by ~:code~, then in reverse order of ~:date~.
1431
1673
 
1432
- #+BEGIN_SRC ruby :wrap EXAMPLE
1433
- tab1.order_by(:code, :date!) \
1434
- .to_aoa
1674
+ #+BEGIN_SRC ruby
1675
+ tab1.order_by(:code, :date!).to_aoa
1435
1676
  #+END_SRC
1436
1677
 
1437
- #+begin_EXAMPLE
1438
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1439
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1440
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1441
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1442
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1443
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1444
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1445
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1446
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1447
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1448
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1449
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1450
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1451
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1452
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
1453
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
1454
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1455
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1456
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
1457
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
1458
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1459
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1460
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1461
- #+end_EXAMPLE
1678
+ #+RESULTS:
1679
+ #+begin_example
1680
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1681
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1682
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1683
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1684
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1685
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1686
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1687
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1688
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1689
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1690
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1691
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1692
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1693
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1694
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
1695
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
1696
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1697
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
1698
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
1699
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
1700
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1701
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1702
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1703
+ #+end_example
1462
1704
 
1463
1705
  The interesting thing about ~order_by~ is that, while it ignores groups in its
1464
1706
  input, it adds group boundaries in the output table at those rows where the sort
1465
1707
  keys change. Thus, in each group, ~:code~ and ~:date~ are the same, and when
1466
1708
  either changes, ~order_by~ inserts a group boundary.
1467
1709
 
1710
+ Sorting with ~order_by~ is stable: keys that are equal maintain the
1711
+ order they had in the unsorted table.
1712
+
1468
1713
  *** Order_with
1469
1714
  The ~order_with~ method is a convenient combination of ~select~ and
1470
1715
  ~order_by~. It takes a single string expression as an argument to serve as a
@@ -1473,48 +1718,49 @@ optional trailing ~!~ to indicate reverse sort. The resulting table has an
1473
1718
  additional column called ~:sort_key~ with the expression evaluated for each
1474
1719
  row, and the table is sorted as with ~order_by~ on that column.
1475
1720
 
1476
- #+BEGIN_SRC ruby :wrap EXAMPLE
1721
+ #+BEGIN_SRC ruby
1477
1722
  tab1.order_with('price * shares').to_aoa
1478
1723
  #+END_SRC
1479
1724
 
1480
- #+begin_EXAMPLE
1481
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp | Sort Key |
1482
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1483
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 742.5 |
1484
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1485
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 770.0 |
1486
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1487
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 | 825.0 |
1488
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1489
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1530.0 |
1490
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1491
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1550.0 |
1492
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1493
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 | 3875.0 |
1494
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1495
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0 |
1496
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0 |
1497
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1498
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0 |
1499
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0 |
1500
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1501
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 | 21198.15 |
1502
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1503
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 | 23971.25 |
1504
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1505
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 | 30000.0 |
1506
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1507
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0 |
1508
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0 |
1509
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1510
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 | 43560.15 |
1511
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1512
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 | 51423.05 |
1513
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1514
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 | 72580.0 |
1515
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------+----------|
1516
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 | 390285.0 |
1517
- #+end_EXAMPLE
1725
+ #+RESULTS:
1726
+ #+begin_example
1727
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp | Sort Key |
1728
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1729
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 742.5000 |
1730
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1731
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 | 770.0000 |
1732
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1733
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 | 825.0000 |
1734
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1735
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1530.0000 |
1736
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1737
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 | 1550.0000 |
1738
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1739
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 | 3875.0000 |
1740
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1741
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0000 |
1742
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 | 6000.0000 |
1743
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1744
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0000 |
1745
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 | 7600.0000 |
1746
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1747
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 | 21198.1500 |
1748
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1749
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 | 23971.2500 |
1750
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1751
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 | 30000.0000 |
1752
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1753
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0000 |
1754
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 | 35485.0000 |
1755
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1756
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 | 43560.1500 |
1757
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1758
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 | 51423.0500 |
1759
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1760
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 | 72580.0000 |
1761
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------+-------------|
1762
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 | 390285.0000 |
1763
+ #+end_example
1518
1764
 
1519
1765
  *** Group_by
1520
1766
  Like ~order_by~, ~group_by~ takes a set of parameters of column header symbols,
@@ -1530,29 +1776,29 @@ For example, let's summarize the ~trades~ table by ~:code~ and ~:price~ again,
1530
1776
  and determine total shares, average price, and a few other features of each
1531
1777
  group:
1532
1778
 
1533
- #+BEGIN_SRC ruby :wrap EXAMPLE
1779
+ #+BEGIN_SRC ruby
1534
1780
  tab1.group_by(:code, :date, price: :avg,
1535
1781
  shares: :sum, lp: :sum, qp: :sum,
1536
- qp10: :all?) \
1537
- .to_aoa { |f| f.format(avg_price: '0.5R') }
1782
+ qp10: :all?).to_aoa { |f| f.format(avg_price: '0.5R') }
1538
1783
  #+END_SRC
1539
1784
 
1540
- #+BEGIN_EXAMPLE
1541
- | Code | Date | Avg Price | Sum Shares | Sum Lp | Sum Qp | All QP10 |
1785
+ #+RESULTS:
1786
+ #+begin_example
1787
+ | Code | Date | Avg Price | Sum Shares | Sum Lp | Sum Qp | All QP10 |
1542
1788
  |------+------------+-----------+------------+--------+--------+----------|
1543
1789
  | P | 2016-11-01 | 7.60714 | 17396 | 2473 | 14923 | F |
1544
1790
  | P | 2016-11-02 | 7.61786 | 69047 | 9945 | 59102 | F |
1545
1791
  | S | 2016-11-01 | 7.58000 | 13011 | 1852 | 11159 | F |
1546
- #+END_EXAMPLE
1792
+ #+end_example
1547
1793
 
1548
1794
  After the grouping column parameters, ~:code~ and ~:date~, there are several
1549
- hash-like "aggregating" parameters where the key is the column to aggregate and
1550
- the value is a symbol for one of several aggregating methods that
1551
- ~FatTable::Column~ objects understand. For example, the ~:avg~ method is applied
1552
- to the :price column so that the output shows the average price in each group.
1553
- The ~:shares~, ~:lp~, and ~:qp~ columns are summed, and the ~:all?~ aggregate is
1554
- applied to one of the boolean fields, that is, it is ~true~ if any of the values
1555
- in that column are ~true~.
1795
+ hash-like "aggregating" parameters where the key is the column to aggregate
1796
+ and the value is a symbol for one of several aggregating methods that
1797
+ ~FatTable::Column~ objects understand. For example, the ~:avg~ method is
1798
+ applied to the :price column so that the output shows the average price in
1799
+ each group. The ~:shares~, ~:lp~, and ~:qp~ columns are summed, and the
1800
+ ~:all?~ aggregate is applied to one of the boolean fields, that is, it is
1801
+ ~true~ if all of the values in that column are ~true~.
1556
1802
 
1557
1803
  Note that the column names in the output of the aggregated columns have the
1558
1804
  name of the aggregating method pre-pended to the column name.
@@ -1603,7 +1849,6 @@ implicit ~order_by~ on the grouping columns is collapsed into a single row.
1603
1849
 
1604
1850
  *** Join
1605
1851
  **** Join Types
1606
-
1607
1852
  So far, all the operations have operated on a single table. ~FatTable~ provides
1608
1853
  several ~join~ methods for combining two tables, each of which takes as
1609
1854
  parameters (1) a second table and (2) except in the case of ~cross_join~, zero
@@ -1640,7 +1885,6 @@ for inclusion in the joined output table.
1640
1885
  M~ rows.
1641
1886
 
1642
1887
  **** Join Expressions
1643
-
1644
1888
  For each of the join types, if no join expressions are given, the tables will be
1645
1889
  joined on columns having the same column header in both tables, and the join
1646
1890
  condition is satisfied when all the values in those columns are equal. If the
@@ -1668,12 +1912,11 @@ local variables within the expression, but the instance variables ~@row~ and
1668
1912
  ~@group~ are not.
1669
1913
 
1670
1914
  **** Join Examples
1671
-
1672
1915
  The following examples are taken from the [[https://www.tutorialspoint.com/postgresql/postgresql_using_joins.htm][Postgresql tutorial]], with some slight
1673
1916
  modifications. The examples will use the following two tables, which are also
1674
1917
  available in ~ft_console~ as ~@tab_a~ and ~@tab_b~:
1675
1918
 
1676
- #+BEGIN_SRC ruby :wrap EXAMPLE :results silent
1919
+ #+BEGIN_SRC ruby :results silent
1677
1920
  tab_a_str = <<-EOS
1678
1921
  | Id | Name | Age | Address | Salary | Join Date |
1679
1922
  |----+-------+-----+------------+--------+------------|
@@ -1697,145 +1940,153 @@ available in ~ft_console~ as ~@tab_a~ and ~@tab_b~:
1697
1940
  #+END_SRC
1698
1941
 
1699
1942
  Here is ~tab_a~:
1700
- #+begin_src ruby :wrap EXAMPLE
1943
+ #+begin_src ruby
1701
1944
  tab_a = FatTable.from_org_string(tab_a_str)
1702
1945
  tab_a.to_aoa
1703
1946
  #+end_src
1704
1947
 
1705
- #+begin_EXAMPLE
1706
- | Id | Name | Age | Address | Salary | Join Date |
1948
+ #+RESULTS:
1949
+ #+begin_example
1950
+ | Id | Name | Age | Address | Salary | Join Date |
1707
1951
  |----+-------+-----+------------+--------+------------|
1708
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
1709
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
1710
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
1711
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
1712
- | 2 | Allen | 25 | Texas | | 2005-07-13 |
1713
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
1714
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
1952
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
1953
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
1954
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
1955
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
1956
+ | 2 | Allen | 25 | Texas | | 2005-07-13 |
1957
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
1958
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
1715
1959
  | 10 | James | 45 | Texas | 5000 | |
1716
- #+end_EXAMPLE
1960
+ #+end_example
1717
1961
 
1718
1962
  And ~tab_b~:
1719
- #+begin_src ruby :wrap EXAMPLE
1963
+ #+begin_src ruby
1720
1964
  tab_b = FatTable.from_org_string(tab_b_str)
1721
1965
  tab_b.to_aoa
1722
1966
  #+end_src
1723
1967
 
1724
- #+begin_EXAMPLE
1968
+ #+RESULTS:
1969
+ #+begin_example
1725
1970
  | Id | Dept | Emp Id |
1726
1971
  |----+-------------+--------|
1727
- | 1 | IT Billing | 1 |
1728
- | 2 | Engineering | 2 |
1729
- | 3 | Finance | 7 |
1730
- #+end_EXAMPLE
1972
+ | 1 | IT Billing | 1 |
1973
+ | 2 | Engineering | 2 |
1974
+ | 3 | Finance | 7 |
1975
+ #+end_example
1731
1976
 
1732
1977
  ***** Inner Joins
1733
1978
  With no join expression arguments, the tables are joined when their sole common
1734
1979
  field, ~:id~, is equal in both tables. The result is the natural join of the
1735
1980
  two tables.
1736
1981
 
1737
- #+BEGIN_SRC ruby :wrap EXAMPLE
1982
+ #+BEGIN_SRC ruby
1738
1983
  tab_a.join(tab_b).to_aoa
1739
1984
  #+END_SRC
1740
1985
 
1741
- #+BEGIN_EXAMPLE
1742
- | Id | Name | Age | Address | Salary | Join Date | Dept | Emp Id |
1986
+ #+RESULTS:
1987
+ #+begin_example
1988
+ | Id | Name | Age | Address | Salary | Join Date | Dept | Emp Id |
1743
1989
  |----+-------+-----+------------+--------+------------+-------------+--------|
1744
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | IT Billing | 1 |
1745
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | Finance | 7 |
1746
- | 2 | Allen | 25 | Texas | | 2005-07-13 | Engineering | 2 |
1747
- #+END_EXAMPLE
1990
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | IT Billing | 1 |
1991
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | Finance | 7 |
1992
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | Engineering | 2 |
1993
+ #+end_example
1748
1994
 
1749
1995
  But the natural join joined employee IDs in the first table and department IDs
1750
1996
  in the second table. To correct this, we need to explicitly state the columns we
1751
1997
  want to join on in each table by disambiguating them with ~_a~ and ~_b~
1752
1998
  suffixes:
1753
1999
 
1754
- #+BEGIN_SRC ruby :wrap EXAMPLE
2000
+ #+BEGIN_SRC ruby
1755
2001
  tab_a.join(tab_b, :id_a, :emp_id_b).to_aoa
1756
2002
  #+END_SRC
1757
2003
 
1758
- #+BEGIN_EXAMPLE
1759
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept |
2004
+ #+RESULTS:
2005
+ #+begin_example
2006
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept |
1760
2007
  |----+-------+-----+------------+--------+------------+------+-------------|
1761
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing |
1762
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering |
1763
- #+END_EXAMPLE
2008
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing |
2009
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering |
2010
+ #+end_example
1764
2011
 
1765
2012
  Instead of using the disambiguated column names as symbols, we could also use a
1766
2013
  string containing a ruby expression. Within the expression, the column names
1767
2014
  should be treated as local variables:
1768
2015
 
1769
- #+BEGIN_SRC ruby :wrap EXAMPLE
2016
+ #+BEGIN_SRC ruby
1770
2017
  tab_a.join(tab_b, 'id_a == emp_id_b').to_aoa
1771
2018
  #+END_SRC
1772
2019
 
1773
- #+BEGIN_EXAMPLE
1774
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
2020
+ #+RESULTS:
2021
+ #+begin_example
2022
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
1775
2023
  |----+-------+-----+------------+--------+------------+------+-------------+--------|
1776
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
1777
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
1778
- #+END_EXAMPLE
2024
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
2025
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
2026
+ #+end_example
1779
2027
 
1780
2028
  ***** Left and Right Joins
1781
2029
  In left join, all the rows of ~tab_a~ are included in the output, augmented by
1782
2030
  the matching columns of ~tab_b~ and augmented with nils where there is no match:
1783
2031
 
1784
- #+BEGIN_SRC ruby :wrap EXAMPLE
2032
+ #+BEGIN_SRC ruby
1785
2033
  tab_a.left_join(tab_b, 'id_a == emp_id_b').to_aoa
1786
2034
  #+END_SRC
1787
2035
 
1788
- #+BEGIN_EXAMPLE
1789
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
2036
+ #+RESULTS:
2037
+ #+begin_example
2038
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
1790
2039
  |----+-------+-----+------------+--------+------------+------+-------------+--------|
1791
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
1792
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | | | |
1793
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | | | |
1794
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 | | | |
1795
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
1796
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | | | |
1797
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 | | | |
2040
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
2041
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | | | |
2042
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | | | |
2043
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 | | | |
2044
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
2045
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | | | |
2046
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 | | | |
1798
2047
  | 10 | James | 45 | Texas | 5000 | | | | |
1799
- #+END_EXAMPLE
2048
+ #+end_example
1800
2049
 
1801
2050
  In a right join, all the rows of ~tab_b~ are included in the output, augmented
1802
2051
  by the matching columns of ~tab_a~ and augmented with nils where there is no
1803
2052
  match:
1804
2053
 
1805
- #+BEGIN_SRC ruby :wrap EXAMPLE
2054
+ #+BEGIN_SRC ruby
1806
2055
  tab_a.right_join(tab_b, 'id_a == emp_id_b').to_aoa
1807
2056
  #+END_SRC
1808
2057
 
1809
- #+BEGIN_EXAMPLE
1810
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
2058
+ #+RESULTS:
2059
+ #+begin_example
2060
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
1811
2061
  |----+-------+-----+------------+--------+------------+------+-------------+--------|
1812
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
1813
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
1814
- | | | | | | | 3 | Finance | 7 |
1815
- #+END_EXAMPLE
2062
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
2063
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
2064
+ | | | | | | | 3 | Finance | 7 |
2065
+ #+end_example
1816
2066
 
1817
2067
  ***** Full Join
1818
2068
  A full join combines the effects of a left join and a right join. All the rows
1819
2069
  from both tables are included in the output augmented by columns of the other
1820
2070
  table where the join expression is satisfied and augmented with nils otherwise.
1821
2071
 
1822
- #+BEGIN_SRC ruby :wrap EXAMPLE
2072
+ #+BEGIN_SRC ruby
1823
2073
  tab_a.full_join(tab_b, 'id_a == emp_id_b').to_aoa
1824
2074
  #+END_SRC
1825
2075
 
1826
- #+BEGIN_EXAMPLE
1827
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
2076
+ #+RESULTS:
2077
+ #+begin_example
2078
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
1828
2079
  |----+-------+-----+------------+--------+------------+------+-------------+--------|
1829
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
1830
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | | | |
1831
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | | | |
1832
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 | | | |
1833
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
1834
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | | | |
1835
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 | | | |
2080
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
2081
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | | | |
2082
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | | | |
2083
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 | | | |
2084
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
2085
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | | | |
2086
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 | | | |
1836
2087
  | 10 | James | 45 | Texas | 5000 | | | | |
1837
- | | | | | | | 3 | Finance | 7 |
1838
- #+END_EXAMPLE
2088
+ | | | | | | | 3 | Finance | 7 |
2089
+ #+end_example
1839
2090
 
1840
2091
  ***** Cross Join
1841
2092
  Finally, a cross join outputs every row of ~tab_a~ augmented with every row of
@@ -1843,38 +2094,39 @@ Finally, a cross join outputs every row of ~tab_a~ augmented with every row of
1843
2094
  ~N~ rows and ~tab_b~ has ~M~ rows, the output table will have ~N * M~ rows.
1844
2095
  So be careful lest you consume all your computer's memory.
1845
2096
 
1846
- #+BEGIN_SRC ruby :wrap EXAMPLE
2097
+ #+BEGIN_SRC ruby
1847
2098
  tab_a.cross_join(tab_b).to_aoa
1848
2099
  #+END_SRC
1849
2100
 
1850
- #+BEGIN_EXAMPLE
1851
- | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
2101
+ #+RESULTS:
2102
+ #+begin_example
2103
+ | Id | Name | Age | Address | Salary | Join Date | Id B | Dept | Emp Id |
1852
2104
  |----+-------+-----+------------+--------+------------+------+-------------+--------|
1853
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
1854
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 2 | Engineering | 2 |
1855
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 3 | Finance | 7 |
1856
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 1 | IT Billing | 1 |
1857
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 2 | Engineering | 2 |
1858
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 3 | Finance | 7 |
1859
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 1 | IT Billing | 1 |
1860
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 2 | Engineering | 2 |
1861
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 3 | Finance | 7 |
1862
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 1 | IT Billing | 1 |
1863
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 2 | Engineering | 2 |
1864
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 3 | Finance | 7 |
1865
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 1 | IT Billing | 1 |
1866
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
1867
- | 2 | Allen | 25 | Texas | | 2005-07-13 | 3 | Finance | 7 |
1868
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 1 | IT Billing | 1 |
1869
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 2 | Engineering | 2 |
1870
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 3 | Finance | 7 |
1871
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 1 | IT Billing | 1 |
1872
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 2 | Engineering | 2 |
1873
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 3 | Finance | 7 |
1874
- | 10 | James | 45 | Texas | 5000 | | 1 | IT Billing | 1 |
1875
- | 10 | James | 45 | Texas | 5000 | | 2 | Engineering | 2 |
1876
- | 10 | James | 45 | Texas | 5000 | | 3 | Finance | 7 |
1877
- #+END_EXAMPLE
2105
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 1 | IT Billing | 1 |
2106
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 2 | Engineering | 2 |
2107
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 | 3 | Finance | 7 |
2108
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 1 | IT Billing | 1 |
2109
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 2 | Engineering | 2 |
2110
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 | 3 | Finance | 7 |
2111
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 1 | IT Billing | 1 |
2112
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 2 | Engineering | 2 |
2113
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 | 3 | Finance | 7 |
2114
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 1 | IT Billing | 1 |
2115
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 2 | Engineering | 2 |
2116
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 | 3 | Finance | 7 |
2117
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 1 | IT Billing | 1 |
2118
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 2 | Engineering | 2 |
2119
+ | 2 | Allen | 25 | Texas | | 2005-07-13 | 3 | Finance | 7 |
2120
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 1 | IT Billing | 1 |
2121
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 2 | Engineering | 2 |
2122
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 | 3 | Finance | 7 |
2123
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 1 | IT Billing | 1 |
2124
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 2 | Engineering | 2 |
2125
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 | 3 | Finance | 7 |
2126
+ | 10 | James | 45 | Texas | 5000 | | 1 | IT Billing | 1 |
2127
+ | 10 | James | 45 | Texas | 5000 | | 2 | Engineering | 2 |
2128
+ | 10 | James | 45 | Texas | 5000 | | 3 | Finance | 7 |
2129
+ #+end_example
1878
2130
 
1879
2131
  *** Set Operations
1880
2132
  ~FatTable~ can perform several set operations on pairs of tables. In order for
@@ -1886,66 +2138,67 @@ We'll use the following two set-compatible tables in the examples. They each
1886
2138
  have some duplicates and some group boundaries so you can see the effect of the
1887
2139
  set operations on duplicates and groups.
1888
2140
 
1889
- #+BEGIN_SRC ruby :wrap EXAMPLE
2141
+ #+BEGIN_SRC ruby
1890
2142
  tab1.to_aoa
1891
2143
  #+END_SRC
1892
2144
 
1893
- #+BEGIN_EXAMPLE
1894
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1895
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1896
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1897
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1898
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1899
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1900
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1901
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
1902
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
1903
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1904
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1905
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1906
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
1907
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
1908
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1909
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1910
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1911
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1912
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1913
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1914
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
1915
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1916
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1917
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1918
- #+END_EXAMPLE
2145
+ #+RESULTS:
2146
+ #+begin_example
2147
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2148
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2149
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2150
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2151
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2152
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2153
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2154
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2155
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2156
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2157
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2158
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2159
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2160
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2161
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2162
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2163
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2164
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2165
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2166
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2167
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2168
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2169
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2170
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2171
+ #+end_example
1919
2172
 
1920
- #+BEGIN_SRC ruby :wrap EXAMPLE
2173
+ #+BEGIN_SRC ruby
1921
2174
  tab2.to_aoa
1922
2175
  #+END_SRC
1923
2176
 
1924
- #+BEGIN_EXAMPLE
1925
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1926
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
1927
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1928
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1929
- | T017 | 2016-11-01 | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
1930
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
1931
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
1932
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
1933
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1934
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1935
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
1936
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1937
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1938
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1939
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1940
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
1941
- | T019 | 2017-01-15 | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
1942
- | T020 | 2017-01-19 | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
1943
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
1944
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
1945
- #+END_EXAMPLE
2177
+ #+RESULTS:
2178
+ #+begin_example
2179
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2180
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2181
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2182
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2183
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2184
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2185
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2186
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2187
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2188
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2189
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2190
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2191
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2192
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2193
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2194
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2195
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2196
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2197
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2198
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2199
+ #+end_example
1946
2200
 
1947
2201
  **** Unions
1948
-
1949
2202
  Two tables that are set-compatible can be combined with the ~union~ or
1950
2203
  ~union_all~ methods so that the rows of both tables appear in the output. In the
1951
2204
  output table, the headers of the receiver table are used. You can use ~select~
@@ -1956,292 +2209,297 @@ Any group boundaries in the input tables are destroyed by ~union~ but are
1956
2209
  preserved by ~union_all~. In addition, ~union_all~ (but not ~union~) adds a
1957
2210
  group boundary between the rows of the two input tables.
1958
2211
 
1959
- #+BEGIN_SRC ruby :wrap EXAMPLE
2212
+ #+BEGIN_SRC ruby
1960
2213
  tab1.union(tab2).to_aoa
1961
2214
  #+END_SRC
1962
2215
 
1963
- #+BEGIN_EXAMPLE
1964
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1965
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
1966
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1967
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1968
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1969
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
1970
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
1971
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
1972
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1973
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
1974
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
1975
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
1976
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1977
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
1978
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
1979
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
1980
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
1981
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
1982
- | T017 | 2016-11-01 | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
1983
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
1984
- | T019 | 2017-01-15 | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
1985
- | T020 | 2017-01-19 | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
1986
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
1987
- #+END_EXAMPLE
2216
+ #+RESULTS:
2217
+ #+begin_example
2218
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2219
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2220
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2221
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2222
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2223
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2224
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2225
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2226
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2227
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2228
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2229
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2230
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2231
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2232
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2233
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2234
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2235
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2236
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2237
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2238
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2239
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2240
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2241
+ #+end_example
1988
2242
 
1989
- #+BEGIN_SRC ruby :wrap EXAMPLE
2243
+ #+BEGIN_SRC ruby
1990
2244
  tab1.union_all(tab2).to_aoa
1991
2245
  #+END_SRC
1992
2246
 
1993
- #+BEGIN_EXAMPLE
1994
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
1995
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
1996
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
1997
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
1998
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
1999
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2000
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2001
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2002
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2003
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2004
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2005
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2006
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2007
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2008
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2009
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2010
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2011
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2012
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2013
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2014
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2015
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2016
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2017
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2018
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2019
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2020
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2021
- | T017 | 2016-11-01 | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2022
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2023
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2024
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2025
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2026
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2027
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2028
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2029
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2030
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2031
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2032
- |------+------------+------+-------+-----+------+--------+-------+-------+--------+--------|
2033
- | T019 | 2017-01-15 | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2034
- | T020 | 2017-01-19 | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2035
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2036
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2037
- #+END_EXAMPLE
2247
+ #+RESULTS:
2248
+ #+begin_example
2249
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2250
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2251
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2252
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2253
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2254
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2255
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2256
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2257
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2258
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2259
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2260
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2261
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2262
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2263
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2264
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2265
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2266
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2267
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2268
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2269
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2270
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2271
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2272
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2273
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2274
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2275
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2276
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2277
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2278
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2279
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2280
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2281
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2282
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2283
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2284
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2285
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2286
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2287
+ |------+------------+------+--------+-----+------+--------+-------+-------+--------+--------|
2288
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2289
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2290
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2291
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2292
+ #+end_example
2038
2293
 
2039
2294
  **** Intersections
2040
-
2041
2295
  The ~intersect~ method returns a table having only rows common to both tables,
2042
2296
  eliminating any duplicate rows in the result.
2043
2297
 
2044
- #+BEGIN_SRC ruby :wrap EXAMPLE
2298
+ #+BEGIN_SRC ruby
2045
2299
  tab1.intersect(tab2).to_aoa
2046
2300
  #+END_SRC
2047
2301
 
2048
- #+BEGIN_EXAMPLE
2049
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2050
- |------+------------+------+-------+-----+------+--------+-----+------+--------+--------|
2051
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2052
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2053
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2054
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2055
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2056
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2057
- #+END_EXAMPLE
2302
+ #+RESULTS:
2303
+ #+begin_example
2304
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2305
+ |------+------------+------+--------+-----+------+--------+-----+------+--------+--------|
2306
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2307
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2308
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2309
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2310
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2311
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2312
+ #+end_example
2058
2313
 
2059
2314
  With ~intersect_all~, all the rows of the first table, including duplicates, are
2060
2315
  included in the result if they also occur in the second table. However,
2061
2316
  duplicates in the second table do not appear.
2062
2317
 
2063
- #+BEGIN_SRC ruby :wrap EXAMPLE
2318
+ #+BEGIN_SRC ruby
2064
2319
  tab1.intersect_all(tab2).to_aoa
2065
2320
  #+END_SRC
2066
2321
 
2067
- #+BEGIN_EXAMPLE
2068
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2069
- |------+------------+------+-------+-----+------+--------+-----+------+--------+--------|
2070
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2071
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2072
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2073
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2074
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2075
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2076
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2077
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2078
- #+END_EXAMPLE
2322
+ #+RESULTS:
2323
+ #+begin_example
2324
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2325
+ |------+------------+------+--------+-----+------+--------+-----+------+--------+--------|
2326
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2327
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2328
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2329
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2330
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2331
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2332
+ #+end_example
2079
2333
 
2080
2334
  As a result, it makes a difference which table is the receiver of the
2081
2335
  ~intersect_all~ method call and which is the argument. In other words, order of
2082
2336
  operation matters.
2083
2337
 
2084
- #+BEGIN_SRC ruby :wrap EXAMPLE
2338
+ #+BEGIN_SRC ruby
2085
2339
  tab2.intersect_all(tab1).to_aoa
2086
2340
  #+END_SRC
2087
2341
 
2088
- #+BEGIN_EXAMPLE
2089
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2090
- |------+------------+------+-------+-----+------+--------+-----+------+--------+--------|
2091
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2092
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2093
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2094
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2095
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2096
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2097
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2098
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2099
- #+END_EXAMPLE
2342
+ #+RESULTS:
2343
+ #+begin_example
2344
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2345
+ |------+------------+------+--------+-----+------+--------+-----+------+--------+--------|
2346
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2347
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2348
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2349
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2350
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2351
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2352
+ #+end_example
2100
2353
 
2101
2354
  **** Set Differences with Except
2102
-
2103
2355
  You can use the ~except~ method to delete from a table any rows that occur in
2104
2356
  another table, that is, compute the set difference between the tables.
2105
2357
 
2106
- #+BEGIN_SRC ruby :wrap EXAMPLE
2358
+ #+BEGIN_SRC ruby
2107
2359
  tab1.except(tab2).to_aoa
2108
2360
  #+END_SRC
2109
2361
 
2110
- #+BEGIN_EXAMPLE
2111
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2112
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
2113
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2114
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2115
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2116
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2117
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2118
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2119
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2120
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2121
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2122
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2123
- #+END_EXAMPLE
2362
+ #+RESULTS:
2363
+ #+begin_example
2364
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2365
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2366
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2367
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2368
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2369
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2370
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2371
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2372
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2373
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2374
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2375
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2376
+ #+end_example
2124
2377
 
2125
2378
  Like subtraction, though, the order of operands matters with set difference
2126
2379
  computed by ~except~.
2127
2380
 
2128
- #+BEGIN_SRC ruby :wrap EXAMPLE
2381
+ #+BEGIN_SRC ruby
2129
2382
  tab2.except(tab1).to_aoa
2130
2383
  #+END_SRC
2131
2384
 
2132
- #+BEGIN_EXAMPLE
2133
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2134
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
2135
- | T017 | 2016-11-01 | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2136
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2137
- | T019 | 2017-01-15 | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2138
- | T020 | 2017-01-19 | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2139
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2140
- #+END_EXAMPLE
2385
+ #+RESULTS:
2386
+ #+begin_example
2387
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2388
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2389
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2390
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2391
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2392
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2393
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2394
+ #+end_example
2141
2395
 
2142
2396
  As with ~intersect_all~, ~except_all~ includes any duplicates in the first,
2143
2397
  receiver table, but not those in the second, argument table.
2144
2398
 
2145
- #+BEGIN_SRC ruby :wrap EXAMPLE
2399
+ #+BEGIN_SRC ruby
2146
2400
  tab1.except_all(tab2).to_aoa
2147
2401
  #+END_SRC
2148
2402
 
2149
- #+BEGIN_EXAMPLE
2150
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2151
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
2152
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2153
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2154
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2155
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2156
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2157
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2158
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2159
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2160
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2161
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2162
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2163
- #+END_EXAMPLE
2403
+ #+RESULTS:
2404
+ #+begin_example
2405
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2406
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2407
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2408
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2409
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2410
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2411
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2412
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2413
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2414
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2415
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2416
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2417
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2418
+ #+end_example
2164
2419
 
2165
2420
  And, of course, the order of operands matters here as well.
2166
2421
 
2167
- #+BEGIN_SRC ruby :wrap EXAMPLE
2422
+ #+BEGIN_SRC ruby
2168
2423
  tab2.except_all(tab1).to_aoa
2169
2424
  #+END_SRC
2170
2425
 
2171
- #+BEGIN_EXAMPLE
2172
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2173
- |------+------------+------+-------+-----+------+--------+-------+------+--------+--------|
2174
- | T017 | 2016-11-01 | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2175
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2176
- | T018 | 2016-11-01 | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2177
- | T019 | 2017-01-15 | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2178
- | T020 | 2017-01-19 | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2179
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2180
- | T021 | 2017-01-23 | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2181
- #+END_EXAMPLE
2426
+ #+RESULTS:
2427
+ #+begin_example
2428
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2429
+ |------+------------+------+--------+-----+------+--------+-------+------+--------+--------|
2430
+ | T017 | 2016-11-01 | P | 8.3000 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
2431
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2432
+ | T018 | 2016-11-01 | S | 7.1520 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
2433
+ | T019 | 2017-01-15 | S | 8.7500 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
2434
+ | T020 | 2017-01-19 | S | 8.2500 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
2435
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2436
+ | T021 | 2017-01-23 | P | 7.1600 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
2437
+ #+end_example
2182
2438
 
2183
2439
  *** Uniq (aka Distinct)
2184
2440
  The ~uniq~ method takes no arguments and simply removes any duplicate rows from
2185
2441
  the input table. The ~distinct~ method is an alias for ~uniq~. Any groups in
2186
2442
  the input table are lost.
2187
2443
 
2188
- #+BEGIN_SRC ruby :wrap EXAMPLE
2444
+ #+BEGIN_SRC ruby
2189
2445
  tab1.uniq.to_aoa
2190
2446
  #+END_SRC
2191
2447
 
2192
- #+BEGIN_EXAMPLE
2193
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2194
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
2195
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2196
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2197
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2198
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2199
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2200
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2201
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2202
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2203
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2204
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2205
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2206
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2207
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2208
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2209
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2210
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2211
- #+END_EXAMPLE
2448
+ #+RESULTS:
2449
+ #+begin_example
2450
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2451
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2452
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2453
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2454
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2455
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2456
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2457
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2458
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2459
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2460
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2461
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2462
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2463
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2464
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2465
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2466
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2467
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2468
+ #+end_example
2212
2469
 
2213
2470
  *** Remove groups with degroup!
2214
2471
  Finally, it is sometimes helpful to remove any group boundaries from a table.
2215
2472
  You can do this with ~.degroup!~, which, together with ~force_string!~, are
2216
2473
  the only operations that mutate their receiver tables.
2217
2474
 
2218
- #+BEGIN_SRC ruby :wrap EXAMPLE
2475
+ #+BEGIN_SRC ruby
2219
2476
  tab1.degroup!.to_aoa
2220
2477
  #+END_SRC
2221
2478
 
2222
- #+BEGIN_EXAMPLE
2223
- | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2224
- |------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
2225
- | T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2226
- | T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2227
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2228
- | T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2229
- | T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2230
- | T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2231
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2232
- | T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2233
- | T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2234
- | T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2235
- | T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2236
- | T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2237
- | T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2238
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2239
- | T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2240
- | T013 | 2016-11-02 | P | 7.35 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2241
- | T014 | 2016-11-02 | P | 7.45 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2242
- | T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2243
- | T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2244
- #+END_EXAMPLE
2479
+ #+RESULTS:
2480
+ #+begin_example
2481
+ | Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
2482
+ |------+------------+------+--------+-----+------+--------+------+-------+--------+--------|
2483
+ | T001 | 2016-11-01 | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2484
+ | T002 | 2016-11-01 | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2485
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2486
+ | T003 | 2016-11-01 | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
2487
+ | T004 | 2016-11-01 | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
2488
+ | T005 | 2016-11-01 | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
2489
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2490
+ | T006 | 2016-11-01 | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
2491
+ | T007 | 2016-11-01 | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
2492
+ | T008 | 2016-11-01 | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
2493
+ | T009 | 2016-11-01 | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
2494
+ | T010 | 2016-11-01 | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
2495
+ | T011 | 2016-11-02 | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
2496
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2497
+ | T012 | 2016-11-02 | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
2498
+ | T013 | 2016-11-02 | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
2499
+ | T014 | 2016-11-02 | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
2500
+ | T015 | 2016-11-02 | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
2501
+ | T016 | 2016-11-02 | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
2502
+ #+end_example
2245
2503
 
2246
2504
  ** Formatting Tables
2247
2505
  Besides creating and operating on tables, you may want to display the resulting
@@ -2262,7 +2520,6 @@ but ruby data structures, and for them, things such as alignment are irrelevant.
2262
2520
 
2263
2521
  *** Available Formatter Output Targets
2264
2522
  **** Output Media
2265
-
2266
2523
  ~FatTable~ supports the following output targets for its tables:
2267
2524
 
2268
2525
  - Text :: form the table with ACSII characters,
@@ -2289,11 +2546,12 @@ that, unlike to ~to_org~ formatter shown below, the intersections of lines are
2289
2546
  represented by a ~+~ character. Embelishments such as color, bold, and so
2290
2547
  forth are ignored.
2291
2548
 
2292
- #+BEGIN_SRC ruby :wrap EXAMPLE
2549
+ #+BEGIN_SRC ruby
2293
2550
  tab_a.to_text
2294
2551
  #+end_SRC
2295
2552
 
2296
- #+BEGIN_EXAMPLE
2553
+ #+RESULTS:
2554
+ #+begin_example
2297
2555
  +====+=======+=====+============+========+============+
2298
2556
  | Id | Name | Age | Address | Salary | Join Date |
2299
2557
  +----+-------+-----+------------+--------+------------+
@@ -2306,49 +2564,51 @@ forth are ignored.
2306
2564
  | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
2307
2565
  | 10 | James | 45 | Texas | 5000 | |
2308
2566
  +====+=======+=====+============+========+============+
2309
- #+END_EXAMPLE
2567
+ #+end_example
2310
2568
 
2311
2569
  ***** To Org
2312
-
2313
- This formatter is designed to format tables in a manner consistent with the
2314
- way tables are drawn within Emacs Org Mode. It also uses nothing by ASCII
2315
- characters to draw the table, but, the intersections of lines are represented
2316
- by a ~|~ character. Embelishments such as color, bold, and so forth are
2317
- ignored. When working in Org Mode, note that Emacs will convert an Array of
2318
- Arrays into an Org Mode table, so when constructing tables programmatically,
2319
- it may be better to use the =to_aoa= formatter shown below.
2320
-
2321
- #+begin_SRC ruby :wrap EXAMPLE
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.
2579
+
2580
+ #+begin_SRC ruby
2322
2581
  tab_a.to_org
2323
2582
  #+end_SRC
2324
2583
 
2325
- #+begin_EXAMPLE
2326
- |----+-------+-----+------------+--------+--------------|
2327
- | Id | Name | Age | Address | Salary | Join Date |
2328
- |----+-------+-----+------------+--------+--------------|
2329
- | 1 | Paul | 32 | California | 20000 | [2001-07-13] |
2330
- | 3 | Teddy | 23 | Norway | 20000 | [2007-12-13] |
2331
- | 4 | Mark | 25 | Rich-Mond | 65000 | [2007-12-13] |
2332
- | 5 | David | 27 | Texas | 85000 | [2007-12-13] |
2333
- | 2 | Allen | 25 | Texas | | [2005-07-13] |
2334
- | 8 | Paul | 24 | Houston | 20000 | [2005-07-13] |
2335
- | 9 | James | 44 | Norway | 5000 | [2005-07-13] |
2336
- | 10 | James | 45 | Texas | 5000 | |
2337
- |----+-------+-----+------------+--------+--------------|
2338
- #+end_EXAMPLE
2584
+ #+RESULTS:
2585
+ #+begin_example
2586
+ |----+-------+-----+------------+--------+------------------|
2587
+ | Id | Name | Age | Address | Salary | Join Date |
2588
+ |----+-------+-----+------------+--------+------------------|
2589
+ | 1 | Paul | 32 | California | 20000 | [2001-07-13 Fri] |
2590
+ | 3 | Teddy | 23 | Norway | 20000 | [2007-12-13 Thu] |
2591
+ | 4 | Mark | 25 | Rich-Mond | 65000 | [2007-12-13 Thu] |
2592
+ | 5 | David | 27 | Texas | 85000 | [2007-12-13 Thu] |
2593
+ | 2 | Allen | 25 | Texas | | [2005-07-13 Wed] |
2594
+ | 8 | Paul | 24 | Houston | 20000 | [2005-07-13 Wed] |
2595
+ | 9 | James | 44 | Norway | 5000 | [2005-07-13 Wed] |
2596
+ | 10 | James | 45 | Texas | 5000 | |
2597
+ |----+-------+-----+------------+--------+------------------|
2598
+ #+end_example
2339
2599
 
2340
2600
  ***** To Term
2341
-
2342
2601
  When outputting to a terminal or other device that can interpret ANSI
2343
2602
  characters and escape codes, you can use this formatter to get a prettier
2344
2603
  table. It also allows embelishments such as color and text styles to the
2345
2604
  extent the device supports it.
2346
2605
 
2347
- #+begin_SRC ruby :wrap EXAMPLE
2606
+ #+begin_SRC ruby
2348
2607
  tab_a.to_term
2349
2608
  #+end_SRC
2350
2609
 
2351
- #+begin_EXAMPLE
2610
+ #+RESULTS:
2611
+ #+begin_example
2352
2612
  ╒════╤═══════╤═════╤════════════╤════════╤════════════╕
2353
2613
  │ Id │ Name │ Age │ Address │ Salary │ Join Date │
2354
2614
  ├────┼───────┼─────┼────────────┼────────┼────────────┤
@@ -2361,19 +2621,19 @@ extent the device supports it.
2361
2621
  │ 9 │ James │ 44 │ Norway │ 5000 │ 2005-07-13 │
2362
2622
  │ 10 │ James │ 45 │ Texas │ 5000 │ │
2363
2623
  ╘════╧═══════╧═════╧════════════╧════════╧════════════╛
2364
- #+end_EXAMPLE
2624
+ #+end_example
2365
2625
 
2366
2626
  ***** To LaTeX
2367
-
2368
2627
  This formatter outputs a table in the form suitable for inclusion in a LaTeX
2369
- document using the ~logtable~ package. Natualy it allows embelishments such
2628
+ document using the ~longtable~ package. Natualy it allows embelishments such
2370
2629
  as color and text styles to the full extent of LaTeX's formatting prowess.
2371
2630
 
2372
- #+begin_SRC ruby :wrap EXAMPLE
2631
+ #+begin_SRC ruby
2373
2632
  tab_b.to_latex
2374
2633
  #+end_SRC
2375
2634
 
2376
- #+begin_EXAMPLE
2635
+ #+RESULTS:
2636
+ #+begin_example
2377
2637
  \begin{longtable}{lll}
2378
2638
  Id&
2379
2639
  Dept&
@@ -2389,29 +2649,27 @@ Engineering&
2389
2649
  Finance&
2390
2650
  7\\
2391
2651
  \end{longtable}
2392
- #+end_EXAMPLE
2652
+ #+end_example
2393
2653
 
2394
2654
  ***** To AoA (Array of Arrays)
2395
-
2396
- #+begin_SRC ruby :wrap EXAMPLE
2655
+ #+begin_SRC ruby :results verbatim
2397
2656
  tab_b.to_aoa
2398
2657
  #+end_SRC
2399
2658
 
2400
- #+begin_EXAMPLE
2401
- [["Id", "Dept", "Emp Id"], nil, ["1", "IT Billing", "1"], ["2", "Engineering", "2"],
2402
- ["3", "Finance", "7"]]
2403
- #+end_EXAMPLE
2659
+ #+RESULTS:
2660
+ #+begin_example
2661
+ [["Id", "Dept", "Emp Id"], nil, ["1", "IT Billing", "1"], ["2", "Engineering", "2"], ["3", "Finance", "7"]]
2662
+ #+end_example
2404
2663
 
2405
2664
  ***** To AoH (Array of Hashes)
2406
-
2407
- #+begin_SRC ruby :wrap EXAMPLE
2665
+ #+begin_SRC ruby :results verbatim
2408
2666
  tab_b.to_aoh
2409
2667
  #+end_SRC
2410
2668
 
2411
- #+begin_EXAMPLE
2412
- [{:id=>"1", :dept=>"IT Billing", :emp_id=>"1"}, {:id=>"2", :dept=>"Engineering", :emp_id=>"2"},
2413
- {:id=>"3", :dept=>"Finance", :emp_id=>"7"}]
2414
- #+end_EXAMPLE
2669
+ #+RESULTS:
2670
+ #+begin_example
2671
+ [{id: "1", dept: "IT Billing", emp_id: "1"}, {id: "2", dept: "Engineering", emp_id: "2"}, {id: "3", dept: "Finance", emp_id: "7"}]
2672
+ #+end_example
2415
2673
 
2416
2674
  *** Formatting Directives
2417
2675
  The formatting methods explained in the next section all take formatting
@@ -2419,110 +2677,108 @@ directives as strings in which letters and other characters signify what
2419
2677
  formatting applies. For example, we may apply the formatting directive 'R,$'
2420
2678
  to numbers in a certain part of the table. Each of those characters, and in
2421
2679
  some cases a whole substring, is a single directive. They can appear in any
2422
- order, so '$R,' and ',$R' are equivalent.
2680
+ order, so =$R=, and =,$R= are equivalent.
2423
2681
 
2424
2682
  Here is a list of all the formatting directives that apply to each cell type:
2425
2683
 
2426
2684
  **** All Types as Strings
2427
-
2428
2685
  For a string element, or any an element of any type (since these are applied
2429
2686
  after the element has been converted to a String), the following instructions
2430
2687
  are valid.
2431
2688
 
2432
- - u :: convert the element to all lowercase [default false],
2433
- - U :: convert the element to all uppercase [default false],
2434
- - 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
2435
2692
  each word and lower case the other letters [default false],
2436
- - B ~B :: make the element bold, or turn off bold [default ~B]
2437
- - I ~I :: make the element italic, or turn off italic [default ~I]
2438
- - R :: align the element on the right of the column [default off]
2439
- - L :: align the element on the left of the column [default on]
2440
- - C :: align the element in the center of the column [default off]
2441
- - c[<color_spec>] :: render the element in the given color; the <color_spec>
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>=
2442
2699
  can have the form fgcolor, fgcolor.bgcolor, or .bgcolor, to set the
2443
2700
  foreground or background colors respectively, and each of those can be an
2444
2701
  ANSI or X11 color name in addition to the special color, 'none', which keeps
2445
2702
  the output's default color [default none].
2446
- - _ ~_ :: underline the element, or turn off underline [default off]
2447
- - * ~* :: cause the element to blink, or turn off blink [default off]
2703
+ - =_= :: underline the element, or turn off underline [default off]
2704
+ - =*= :: cause the element to blink, or turn off blink [default off]
2448
2705
 
2449
- 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,
2450
2707
  center it, and color it red on a yellow background. The directives that are
2451
2708
  boolean have negating forms so that, for example, if bold is turned on for all
2452
2709
  columns of a given type, it can be countermanded in formatting directives for
2453
2710
  particular columns.
2454
2711
 
2455
2712
  **** Numeric
2456
-
2457
2713
  For a numeric element, all the instructions valid for string are available, in
2458
2714
  addition to the following:
2459
2715
 
2460
- - , ~, :: insert grouping commas, or do not insert grouping commas [default
2461
- ~,],
2462
- - $ ~$ :: format the number as currency according to the locale, or not
2463
- [default ~$],
2464
- - 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
2465
2721
  left with zeroes as needed, and round the number to the n decimal places and
2466
2722
  include n digits after the decimal point, padding on the right with zeroes
2467
2723
  as needed. If n is negative, the value will be rounded to the left of the
2468
2724
  decimal point: e.g., if n is -2, the number will be rounded to the nearest
2469
- hundred, if -3, to the nearest thousand, etc. [default 0.0]
2470
- - 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~
2471
2727
  form. So a column that is the result of subtracting two :datetime forms will
2472
2728
  result in a :numeric expressed as seconds and can be displayed in hours,
2473
2729
  minutes, and seconds with this formatting instruction. If this directive is
2474
- included, all other numeric directives will be ignored. [default off]
2730
+ included, all other numeric directives will be ignored. (default off)
2475
2731
 
2476
- For example, the directive 'R5.0c[blue]' would right-align the numeric
2732
+ For example, the directive =R5.0c[blue]= would right-align the numeric
2477
2733
  element, pad it on the left with zeros, and color it blue.
2478
2734
 
2479
2735
  **** DateTime
2480
-
2481
2736
  For a ~DateTime~, all the instructions valid for string are available, in
2482
2737
  addition to the following:
2483
2738
 
2484
- - d[fmt] :: apply the format to a ~Date~ or a ~DateTime~ that is a whole day,
2485
- that is that has no or zero hour, minute, and second components, where fmt
2486
- is a valid format string for ~Date#strftime~, otherwise, the datetime will
2487
- be formatted as an ISO 8601 string, YYYY-MM-DD.
2488
- - D[fmt] :: apply the format to a datetime that has at least a non-zero hour
2489
- component where fmt is a valid format string for Date#strftime, otherwise,
2490
- the datetime will be formatted as an ISO 8601 string, YYYY-MM-DD.
2739
+ - =d[fmt]= :: apply the format to a ~Date~ or a ~DateTime~ that is a whole day,
2740
+ that is that has no or zero hour, minute, and second components, where fmt
2741
+ is a valid format string for ~Date#strftime~, otherwise, the datetime will
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=.
2491
2747
 
2492
- For example, 'c[pink]d[%b %-d, %Y]C', would format a date element like 'Sep
2493
- 22, 1957', center it, and color it pink.
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.
2494
2750
 
2495
2751
  **** Boolean
2496
2752
 
2497
2753
  For a boolean cell, all the instructions valid for string are available, in
2498
2754
  addition to the following:
2499
2755
 
2500
- - Y :: print true as ~Y~ and false as ~N~,
2501
- - T :: print true as ~T~ and false as ~F~ [this is the default],
2502
- - X :: print true as ~X~ and false as an empty string '',
2503
- - b[xxx,yyy] :: print true as the string given as ~xxx~ and false as the string
2504
- given as ~yyy~,
2505
- - c[tcolor,fcolor] :: color a true element with ~tcolor~ and a false element
2506
- with ~fcolor~. Each of the colors may be specified in the same manner as
2507
- colors for strings described above.
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.
2508
2764
 
2509
- For example, the directive 'b[Yeppers,Nope]c[green.pink,red.pink]' would
2510
- render a true boolean as ~Yeppers~ colored green on pink and render a false
2511
- boolean as ~Nope~ colored red on pink. See [[https://www.youtube.com/watch?v=oLdFFD8II8U][Yeppers]] for additional information.
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.
2512
2769
 
2513
2770
  **** NilClass
2514
-
2515
2771
  By default, ~nil~ elements are rendered as blank cells, but you can make them
2516
2772
  visible with the following, and in that case, all the formatting instructions
2517
2773
  valid for strings are also available:
2518
2774
 
2519
- - n[niltext] :: render a ~nil~ item with the given niltext [default ''].
2775
+ - =n[<niltext>]= :: render a =nil= item with the given arbitrary string
2776
+ =<niltext>= (default =""=).
2520
2777
 
2521
- For example, you might want to use 'n[-]Cc[purple]' to make nils visible as a
2778
+ For example, you might want to use =n[-]Cc[purple]= to make =nil=s visible as a
2522
2779
  centered purple hyphen.
2523
2780
 
2524
2781
  *** The ~format~ and ~format_for~ methods
2525
-
2526
2782
  Formatters take only two kinds of methods, those that attach footers to a
2527
2783
  table, which are discussed in the next section, and those that specify
2528
2784
  formatting for table cells, which are the subject of this section.
@@ -2546,7 +2802,7 @@ formatting for numerics in general and calls for the ~:id~ column to be padded
2546
2802
  to three digits with zeros on the left (the '3.0' part) and to be centered
2547
2803
  (the 'C' part).
2548
2804
 
2549
- #+BEGIN_SRC ruby :wrap EXAMPLE
2805
+ #+BEGIN_SRC ruby
2550
2806
  tab_a.to_text do |f|
2551
2807
  # Note: blat: is silently ignored
2552
2808
  f.format(numeric: '0.0,R', id: '3.0C', blat: 'B')
@@ -2555,7 +2811,8 @@ to three digits with zeros on the left (the '3.0' part) and to be centered
2555
2811
  end
2556
2812
  #+END_SRC
2557
2813
 
2558
- #+begin_EXAMPLE
2814
+ #+RESULTS:
2815
+ #+begin_example
2559
2816
  +=====+=======+=====+============+========+============+
2560
2817
  | Id | Name | Age | Address | Salary | Join Date |
2561
2818
  +-----+-------+-----+------------+--------+------------+
@@ -2568,7 +2825,7 @@ to three digits with zeros on the left (the '3.0' part) and to be centered
2568
2825
  | 009 | James | 44 | Norway | 5,000 | 2005-07-13 |
2569
2826
  | 010 | James | 45 | Texas | 5,000 | |
2570
2827
  +=====+=======+=====+============+========+============+
2571
- #+end_EXAMPLE
2828
+ #+end_example
2572
2829
 
2573
2830
  In the example, the ~format~ method affects the whole table. Its ~numeric:~
2574
2831
  directive affected the ~:age~ and ~:salary~ columns because their types are
@@ -2583,19 +2840,19 @@ be right-aligned, but the headers are unaffected by it. The ~format_for~ the
2583
2840
  All the other cells in the table, namely the cells in the ~:join_date~ column,
2584
2841
  had the default formatting applied.
2585
2842
 
2586
- **** Table Locations
2843
+ **** Locations within a Table
2587
2844
  In the ~format_for~ formatting method, the first argument names a "location."
2588
2845
  The table is divided into several locations for which separate formatting
2589
2846
  directives may be given. These locations are identified by the following
2590
2847
  symbols:
2591
2848
 
2592
- - :header :: the first row of the output table containing the headers,
2593
- - :footer :: all rows of the table's footers,
2594
- - :gfooter :: all rows of the table's group footers,
2595
- - :body :: all the data rows of the table, that is, those that are neither part
2596
- of the header, footers, or gfooters,
2597
- - :bfirst :: the first row of the table's body, and
2598
- - :gfirst :: the first row in each group in the table's body.
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.
2599
2856
 
2600
2857
  **** Location priority
2601
2858
  Formatting for any given cell depends on its location in the table. The
@@ -2639,13 +2896,14 @@ be applied to all column types. Likewise, since all columns may contain nils,
2639
2896
  the ~NilClass:~ type applies to nils in all columns regardless of the column's
2640
2897
  type.
2641
2898
 
2642
- #+BEGIN_SRC ruby :wrap EXAMPLE
2899
+ #+BEGIN_SRC ruby
2643
2900
  tab_a.to_text do |f|
2644
2901
  f.format(string: 'R', id: '3.0C', nil: 'Cn[-]', salary: 'n[N/A]')
2645
2902
  end
2646
2903
  #+END_SRC
2647
2904
 
2648
- #+BEGIN_EXAMPLE
2905
+ #+RESULTS:
2906
+ #+begin_example
2649
2907
  +=====+=======+=====+============+========+============+
2650
2908
  | Id | Name | Age | Address | Salary | Join Date |
2651
2909
  +-----+-------+-----+------------+--------+------------+
@@ -2653,12 +2911,12 @@ type.
2653
2911
  | 003 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
2654
2912
  | 004 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
2655
2913
  | 005 | David | 27 | Texas | 85000 | 2007-12-13 |
2656
- | 002 | Allen | 25 | Texas | N/A | 2005-07-13 |
2914
+ | 002 | Allen | 25 | Texas | N/A | 2005-07-13 |
2657
2915
  | 008 | Paul | 24 | Houston | 20000 | 2005-07-13 |
2658
- | 009 | James | 44 | Norway | 5000 | 2005-07-13 |
2659
- | 010 | James | 45 | Texas | 5000 | |
2916
+ | 009 | James | 44 | Norway | 5000 | 2005-07-13 |
2917
+ | 010 | James | 45 | Texas | 5000 | - |
2660
2918
  +=====+=======+=====+============+========+============+
2661
- #+END_EXAMPLE
2919
+ #+end_example
2662
2920
 
2663
2921
  The ~string: 'R'~ directive causes all the cells to be right-aligned except
2664
2922
  ~:id~ which specifies centering for the ~:id~ column only. The ~n[N/A]~
@@ -2667,13 +2925,11 @@ but not for other nils, such as in the last row of the ~:join_date~ column.
2667
2925
 
2668
2926
  *** Footers
2669
2927
  **** Adding Footers
2670
-
2671
2928
  You can call the ~foot~, ~gfoot~, ~footer,~ or ~gfooter~, methods on
2672
- ~Formatter~ objects to add footers and group footers. Note that all of these
2673
- methods return a ~Footer~ object that can be accessed to extract the computed
2674
- values. All of these methods return the ~FatTable::Footer~ object so
2675
- constructed. It can be used to access the values and other attributes of the
2676
- 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:
2677
2933
 
2678
2934
  - ~foot(label: label, label_col: nil, **agg_cols)~ :: where ~label~ is a label
2679
2935
  to be placed in the column with header ~label_col~, or, if ommitted, in the
@@ -2725,7 +2981,6 @@ There are also a number of convenience methods for adding common footers:
2725
2981
  columns with the label 'Group Maximum'.
2726
2982
 
2727
2983
  **** Dynamic Labels
2728
-
2729
2984
  Most of the time, you will want a fixed string as the label. However,
2730
2985
  especially in the case of a group footer, you might want a dynamically
2731
2986
  contructed label. You can use a proc or lambda for a label, and it will be
@@ -2734,50 +2989,52 @@ parameter, the footer object itself. This allows you to make the label a
2734
2989
  function of other footer values, for example, you could make the label
2735
2990
  include the most recent year from the date column:
2736
2991
 
2737
- #+begin_src ruby
2992
+ #+begin_src ruby :eval no
2738
2993
  fmtr.foot(label: -> (f) { "Average (latest year #{f.column(:date).max.year})" },
2739
2994
  temp: :avg)
2740
2995
  #+end_src
2741
2996
 
2742
- In the case of a group footer, the lambda or proc may take either one or qtwo parameters.
2997
+ In the case of a group footer, the lambda or proc may take either one or two parameters.
2743
2998
  If it takes one, the parameter is simply the 0-based number of the group:
2744
2999
 
2745
- #+begin_src ruby
3000
+ #+begin_src ruby :eval no
2746
3001
  fmtr.gfoot(label: -> (k) { "Group #{(k+1).to_roman} Average" }, temp: :avg)
2747
3002
  #+end_src
3003
+
2748
3004
  This would format the label with a roman numeral (assuming you defined a
2749
3005
  method to do so) for the group number.
2750
3006
 
2751
3007
  If it takes two arguments, the second argument is the footer itself, as with
2752
3008
  non-group footers:
2753
3009
 
2754
- #+begin_src ruby
3010
+ #+begin_src ruby :eval no
2755
3011
  fmtr.gfoot(label: -> (k, f) { "Year #{f.column(:date, k).max.year} Group #{(k+1).to_roman} Average" },
2756
3012
  temp: :avg)
2757
3013
  #+end_src
3014
+
2758
3015
  This would add the group's year to label, assuming the :date column of the
2759
3016
  footer's table had the same year for each item in the group.
2760
3017
 
2761
3018
  **** Aggregators
2762
-
2763
3019
  When adding a footer with the above methods, you can specify an aggregator for
2764
3020
  each column named in the ~agg_cols~ parameter. There are several candidates
2765
3021
  for what you can use for an aggregator:
2766
3022
 
2767
- - Symbol :: one of the following built-in aggregators: :first, :last, :range,
2768
- :sum, :count, :min, :max, :avg, :var, :pvar, :dev, :pdev, :any?, :all?,
2769
- :none?, and :one?.
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?~.
2770
3026
  + The symbols ending in a question mark are valid only for boolean columns;
2771
- + :count, :first, and :last work with any column type,
2772
- + :min, :max, and :range work with all types except boolean;
2773
- + :sum, works only with numeric columns, and
2774
- + :avg, :var, :dev, :pvar, and :pdev work with numeric or datetime columns.
2775
- In the case of datetime columns, these aggrgators convert the dates to
2776
- julian date numbers, perform the calculation, then convert the result back
2777
- to a datetime object.
2778
- Apart from the built-in aggrgators, you could define your own by opening the
2779
- FatTable::Column class and adding a suitable instance method. In that
2780
- case, the symbol could also refer to the method you defined.
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.
2781
3038
  - String :: using a string as an aggrgegator can result in:
2782
3039
  + the string being converted to an object matching the type of the column
2783
3040
  (for example, using '$1,888' in a numeric column puts the constant number
@@ -2786,9 +3043,9 @@ for what you can use for an aggregator:
2786
3043
  + if the string cannot be parsed as a valid object matching the column's
2787
3044
  type, it is placed literally in the footer field (for example, using
2788
3045
  '(estimated)' can be used to add additional information to the footer)
2789
- - Ruby object :: you can put a number in a numeric footer field, a DateTime
2790
- object in a datetime footer field, or a true or false in a boolean footer
2791
- 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;
2792
3049
  - A Lambda :: finally, you can provide a lambda for performing arbitrary
2793
3050
  calculations and placing the result in the footer field. The number of
2794
3051
  arguments the lambda takes can vary:
@@ -2804,7 +3061,6 @@ for what you can use for an aggregator:
2804
3061
  itself.
2805
3062
 
2806
3063
  **** Footer objects
2807
-
2808
3064
  Each of the methods for adding a footer to a ~Formatter~ returns a ~Footer~ object
2809
3065
  that you can query for attributes of the generated footer, including accessing
2810
3066
  their computed values. Here are the accessors available on a
@@ -2827,32 +3083,33 @@ their computed values. Here are the accessors available on a
2827
3083
  ~k~ to specify which group to access in the case of a group footer.
2828
3084
 
2829
3085
  **** Footer Examples
2830
-
2831
3086
  As a reminder, here is the table, ~tab_a~ defined earlier:
2832
3087
 
2833
- #+BEGIN_SRC ruby :wrap EXAMPLE
3088
+ #+BEGIN_SRC ruby
2834
3089
  tab_a.to_aoa
2835
3090
  #+END_SRC
2836
3091
 
2837
- #+begin_EXAMPLE
2838
- | Id | Name | Age | Address | Salary | Join Date |
3092
+ #+RESULTS:
3093
+ #+begin_example
3094
+ | Id | Name | Age | Address | Salary | Join Date |
2839
3095
  |----+-------+-----+------------+--------+------------|
2840
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
2841
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
2842
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
2843
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
2844
- | 2 | Allen | 25 | Texas | | 2005-07-13 |
2845
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
2846
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3096
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3097
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3098
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3099
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3100
+ | 2 | Allen | 25 | Texas | | 2005-07-13 |
3101
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3102
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
2847
3103
  | 10 | James | 45 | Texas | 5000 | |
2848
- #+end_EXAMPLE
3104
+ #+end_example
2849
3105
 
2850
3106
  ***** Built-in Aggregators
2851
3107
  You can add a footer compute the average of the given columns. You may be
2852
3108
  surprised that you can average a set of dates, but ~:avg~ simply converts the
2853
3109
  dates to Julian numbers, averages that, then converts the result back to a
2854
3110
  date.
2855
- #+BEGIN_SRC ruby :wrap EXAMPLE
3111
+
3112
+ #+BEGIN_SRC ruby
2856
3113
  tab_a.to_text do |f|
2857
3114
  f.format(numeric: '0.0R,', datetime: 'd[%v]D[%v]')
2858
3115
  f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
@@ -2860,7 +3117,8 @@ date.
2860
3117
  end
2861
3118
  #+END_SRC
2862
3119
 
2863
- #+begin_EXAMPLE
3120
+ #+RESULTS:
3121
+ #+begin_example
2864
3122
  +=========+=======+=====+============+========+=============+
2865
3123
  | Id | Name | Age | Address | Salary | Join Date |
2866
3124
  +---------+-------+-----+------------+--------+-------------+
@@ -2877,14 +3135,15 @@ date.
2877
3135
  +---------+-------+-----+------------+--------+-------------+
2878
3136
  | Tally | | 8 | | | |
2879
3137
  +=========+=======+=====+============+========+=============+
2880
- #+end_EXAMPLE
3138
+ #+end_example
2881
3139
 
2882
3140
  ***** String Aggregators
2883
3141
  If the string is convertible into its columns's type, it will be converted to
2884
3142
  that type; otherwise, it will be placed in the footer literally. This example
2885
3143
  also shows how the values from one footer might be used in composing another
2886
3144
  footer.
2887
- #+BEGIN_SRC ruby :wrap EXAMPLE
3145
+
3146
+ #+BEGIN_SRC ruby
2888
3147
  tab_a.to_text do |f|
2889
3148
  f.format(numeric: '0.0R,', datetime: 'd[%v]D[%v]')
2890
3149
  avg_ft = f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
@@ -2900,7 +3159,8 @@ footer.
2900
3159
  end
2901
3160
  #+END_SRC
2902
3161
 
2903
- #+begin_EXAMPLE
3162
+ #+RESULTS:
3163
+ #+begin_example
2904
3164
  +=============+=======+=====+============+========+====================+
2905
3165
  | Id | Name | Age | Address | Salary | Join Date |
2906
3166
  +-------------+-------+-----+------------+--------+--------------------+
@@ -2923,14 +3183,14 @@ footer.
2923
3183
  +-------------+-------+-----+------------+--------+--------------------+
2924
3184
  | Comment | | | | | We're overspending |
2925
3185
  +=============+=======+=====+============+========+====================+
2926
- #+end_EXAMPLE
3186
+ #+end_example
2927
3187
 
2928
3188
  ***** Ruby Objects
2929
3189
  You can make the aggregator an normal ruby object, in which case it is just
2930
3190
  inserted into the footer at the requested location. If its type is the same
2931
3191
  as the column type, it participates in the formatting for that type and
2932
3192
  column.
2933
- #+BEGIN_SRC ruby :wrap EXAMPLE
3193
+ #+BEGIN_SRC ruby
2934
3194
  tab_a.to_text do |f|
2935
3195
  f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
2936
3196
  f.footer('Report Date', age: :count, join_date: Date.today)
@@ -2938,7 +3198,8 @@ column.
2938
3198
  end
2939
3199
  #+END_SRC
2940
3200
 
2941
- #+begin_EXAMPLE
3201
+ #+RESULTS:
3202
+ #+begin_example
2942
3203
  +=============+=======+=====+============+========+=============+
2943
3204
  | Id | Name | Age | Address | Salary | Join Date |
2944
3205
  +-------------+-------+-----+------------+--------+-------------+
@@ -2953,12 +3214,12 @@ column.
2953
3214
  +-------------+-------+-----+------------+--------+-------------+
2954
3215
  | Average | | 31 | | 31,429 | 29-DEC-2005 |
2955
3216
  +-------------+-------+-----+------------+--------+-------------+
2956
- | Report Date | | 8 | | | 20-JAN-2022 |
3217
+ | Report Date | | 8 | | | 23-NOV-2026 |
2957
3218
  +=============+=======+=====+============+========+=============+
2958
- #+end_EXAMPLE
3219
+ #+end_example
2959
3220
 
2960
3221
  But it can be any type. Here we pick a lottery winner from the employee ids.
2961
- #+BEGIN_SRC ruby :wrap EXAMPLE
3222
+ #+BEGIN_SRC ruby
2962
3223
  tab_a.to_text do |f|
2963
3224
  f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
2964
3225
  winner_id = tab_a.column(:id).items.sample
@@ -2967,7 +3228,8 @@ But it can be any type. Here we pick a lottery winner from the employee ids.
2967
3228
  end
2968
3229
  #+END_SRC
2969
3230
 
2970
- #+begin_EXAMPLE
3231
+ #+RESULTS:
3232
+ #+begin_example
2971
3233
  +================+=======+=====+============+========+=============+
2972
3234
  | Id | Name | Age | Address | Salary | Join Date |
2973
3235
  +----------------+-------+-----+------------+--------+-------------+
@@ -2984,7 +3246,7 @@ But it can be any type. Here we pick a lottery winner from the employee ids.
2984
3246
  +----------------+-------+-----+------------+--------+-------------+
2985
3247
  | Lottery Winner | | 8 | | | 4 |
2986
3248
  +================+=======+=====+============+========+=============+
2987
- #+end_EXAMPLE
3249
+ #+end_example
2988
3250
 
2989
3251
  ***** Lambdas
2990
3252
  Perhaps the most flexible form of aggregator is a lambda form. They can take
@@ -3007,7 +3269,7 @@ the things accessible with the footers, including the items in the current
3007
3269
  column, through the ~f.items(c)~ accessor.
3008
3270
 
3009
3271
  Compute the summ of the squares if the items in the ~:age~ column:
3010
- #+BEGIN_SRC ruby :wrap EXAMPLE
3272
+ #+BEGIN_SRC ruby
3011
3273
  tab_a.to_text do |f|
3012
3274
  f.format(numeric: '0.0R,', datetime: 'd[%v]D[%v]')
3013
3275
  f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
@@ -3015,7 +3277,8 @@ Compute the summ of the squares if the items in the ~:age~ column:
3015
3277
  end
3016
3278
  #+END_SRC
3017
3279
 
3018
- #+begin_EXAMPLE
3280
+ #+RESULTS:
3281
+ #+begin_example
3019
3282
  +=========+=======+=====+============+========+=============+
3020
3283
  | Id | Name | Age | Address | Salary | Join Date |
3021
3284
  +---------+-------+-----+------------+--------+-------------+
@@ -3030,13 +3293,13 @@ Compute the summ of the squares if the items in the ~:age~ column:
3030
3293
  +---------+-------+-----+------------+--------+-------------+
3031
3294
  | Average | | 31 | | 31,429 | 29-DEC-2005 |
3032
3295
  +---------+-------+-----+------------+--------+-------------+
3033
- | SSQ | | 90 | | | |
3296
+ | SSQ | | 810 | | | |
3034
3297
  +=========+=======+=====+============+========+=============+
3035
- #+end_EXAMPLE
3298
+ #+end_example
3036
3299
 
3037
3300
  Group the table according to the employee's year of joining, then compute the
3038
3301
  summ of the squares if the ages in each group:
3039
- #+BEGIN_SRC ruby :wrap EXAMPLE
3302
+ #+BEGIN_SRC ruby
3040
3303
  tab_a.order_with('join_date.year').to_text do |f|
3041
3304
  f.format(numeric: '0.0R,', datetime: 'd[%v]D[%v]', sort_key: '0.0~,')
3042
3305
  f.footer('Average', age: :avg, salary: :avg, join_date: :avg)
@@ -3045,7 +3308,8 @@ summ of the squares if the ages in each group:
3045
3308
  end
3046
3309
  #+END_SRC
3047
3310
 
3048
- #+begin_EXAMPLE
3311
+ #+RESULTS:
3312
+ #+begin_example
3049
3313
  +===========+=======+=====+============+========+=============+==========+
3050
3314
  | Id | Name | Age | Address | Salary | Join Date | Sort Key |
3051
3315
  +-----------+-------+-----+------------+--------+-------------+----------+
@@ -3071,9 +3335,9 @@ summ of the squares if the ages in each group:
3071
3335
  +-----------+-------+-----+------------+--------+-------------+----------+
3072
3336
  | Average | | 31 | | 31,429 | 29-DEC-2005 | |
3073
3337
  +-----------+-------+-----+------------+--------+-------------+----------+
3074
- | Total SSQ | | 90 | | | | |
3338
+ | Total SSQ | | 810 | | | | |
3075
3339
  +===========+=======+=====+============+========+=============+==========+
3076
- #+end_EXAMPLE
3340
+ #+end_example
3077
3341
 
3078
3342
  *** Invoking Formatters
3079
3343
  As the examples show, one way to invoke the formatting methods is simply to
@@ -3082,40 +3346,41 @@ call one of the ~to_xxx~ methods directly on a table, which will yield a
3082
3346
  convenient way to do it. But there are a few other ways.
3083
3347
 
3084
3348
  **** By Instantiating a Formatter
3085
-
3086
3349
  You can instantiate a ~XXXFormatter~ object and feed it a table as a
3087
3350
  parameter. There is a Formatter subclass for each target output medium, for
3088
3351
  example, ~AoaFormatter~ will produce a ruby array of arrays. You can then call
3089
3352
  the ~output~ method on the ~XXXFormatter~.
3090
3353
 
3091
- #+BEGIN_SRC ruby :wrap EXAMPLE
3354
+ #+BEGIN_SRC ruby
3092
3355
  FatTable::AoaFormatter.new(tab_a).output
3093
3356
  #+END_SRC
3094
3357
 
3095
- #+BEGIN_EXAMPLE
3096
- | Id | Name | Age | Address | Salary | Join Date |
3358
+ #+RESULTS:
3359
+ #+begin_example
3360
+ | Id | Name | Age | Address | Salary | Join Date |
3097
3361
  |----+-------+-----+------------+--------+------------|
3098
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3099
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3100
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3101
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3102
- | 2 | Allen | 25 | Texas | | 2005-07-13 |
3103
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3104
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3362
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3363
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3364
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3365
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3366
+ | 2 | Allen | 25 | Texas | | 2005-07-13 |
3367
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3368
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3105
3369
  | 10 | James | 45 | Texas | 5000 | |
3106
- #+END_EXAMPLE
3370
+ #+end_example
3107
3371
 
3108
3372
  The ~XXXFormatter.new~ method yields the new instance to any block given, and
3109
3373
  you can call methods on it to affect the formatting of the output:
3110
3374
 
3111
- #+BEGIN_SRC ruby :wrap EXAMPLE
3375
+ #+BEGIN_SRC ruby
3112
3376
  FatTable::AoaFormatter.new(tab_a) do |f|
3113
3377
  f.format(numeric: '0.0,R', id: '3.0C')
3114
3378
  end.output
3115
3379
  #+END_SRC
3116
3380
 
3117
- #+BEGIN_EXAMPLE
3118
- | Id | Name | Age | Address | Salary | Join Date |
3381
+ #+RESULTS:
3382
+ #+begin_example
3383
+ | Id | Name | Age | Address | Salary | Join Date |
3119
3384
  |-----+-------+-----+------------+--------+------------|
3120
3385
  | 001 | Paul | 32 | California | 20,000 | 2001-07-13 |
3121
3386
  | 003 | Teddy | 23 | Norway | 20,000 | 2007-12-13 |
@@ -3125,44 +3390,45 @@ you can call methods on it to affect the formatting of the output:
3125
3390
  | 008 | Paul | 24 | Houston | 20,000 | 2005-07-13 |
3126
3391
  | 009 | James | 44 | Norway | 5,000 | 2005-07-13 |
3127
3392
  | 010 | James | 45 | Texas | 5,000 | |
3128
- #+END_EXAMPLE
3393
+ #+end_example
3129
3394
 
3130
3395
  **** By Using ~FatTable~ module-level method calls
3131
-
3132
3396
  The ~FatTable~ module provides a set of methods of the form ~to_aoa~, ~to_text~,
3133
3397
  etc., to access a ~Formatter~ without having to create an instance yourself.
3134
3398
  Without a block, they apply the default formatting to the table and call the
3135
3399
  ~.output~ method automatically:
3136
3400
 
3137
- #+BEGIN_SRC ruby :wrap EXAMPLE
3401
+ #+BEGIN_SRC ruby
3138
3402
  FatTable.to_aoa(tab_a)
3139
3403
  #+END_SRC
3140
3404
 
3141
- #+BEGIN_EXAMPLE
3142
- | Id | Name | Age | Address | Salary | Join Date |
3405
+ #+RESULTS:
3406
+ #+begin_example
3407
+ | Id | Name | Age | Address | Salary | Join Date |
3143
3408
  |----+-------+-----+------------+--------+------------|
3144
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3145
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3146
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3147
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3148
- | 2 | Allen | 25 | Texas | | 2005-07-13 |
3149
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3150
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3409
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3410
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3411
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3412
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3413
+ | 2 | Allen | 25 | Texas | | 2005-07-13 |
3414
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3415
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3151
3416
  | 10 | James | 45 | Texas | 5000 | |
3152
- #+END_EXAMPLE
3417
+ #+end_example
3153
3418
 
3154
3419
  With a block, these methods yield a ~Formatter~ instance on which you can call
3155
3420
  formatting and footer methods. The ~.output~ method is called on the ~Formatter~
3156
3421
  automatically after the block:
3157
3422
 
3158
- #+BEGIN_SRC ruby :wrap EXAMPLE
3423
+ #+BEGIN_SRC ruby
3159
3424
  FatTable.to_aoa(tab_a) do |f|
3160
3425
  f.format(numeric: '0.0,R', id: '3.0C')
3161
3426
  end
3162
3427
  #+END_SRC
3163
3428
 
3164
- #+BEGIN_EXAMPLE
3165
- | Id | Name | Age | Address | Salary | Join Date |
3429
+ #+RESULTS:
3430
+ #+begin_example
3431
+ | Id | Name | Age | Address | Salary | Join Date |
3166
3432
  |-----+-------+-----+------------+--------+------------|
3167
3433
  | 001 | Paul | 32 | California | 20,000 | 2001-07-13 |
3168
3434
  | 003 | Teddy | 23 | Norway | 20,000 | 2007-12-13 |
@@ -3172,53 +3438,54 @@ automatically after the block:
3172
3438
  | 008 | Paul | 24 | Houston | 20,000 | 2005-07-13 |
3173
3439
  | 009 | James | 44 | Norway | 5,000 | 2005-07-13 |
3174
3440
  | 010 | James | 45 | Texas | 5,000 | |
3175
- #+END_EXAMPLE
3441
+ #+end_example
3176
3442
 
3177
3443
  **** By Calling Methods on Table Objects
3178
-
3179
3444
  Finally, as in many of the examples, you can call methods such as ~to_aoa~,
3180
3445
  ~to_text~, etc., directly on a Table:
3181
3446
 
3182
- #+BEGIN_SRC ruby :wrap EXAMPLE
3447
+ #+BEGIN_SRC ruby
3183
3448
  tab_a.to_aoa
3184
3449
  #+END_SRC
3185
3450
 
3186
- #+BEGIN_EXAMPLE
3187
- | Id | Name | Age | Address | Salary | Join Date |
3451
+ #+RESULTS:
3452
+ #+begin_example
3453
+ | Id | Name | Age | Address | Salary | Join Date |
3188
3454
  |----+-------+-----+------------+--------+------------|
3189
- | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3190
- | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3191
- | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3192
- | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3193
- | 2 | Allen | 25 | Texas | | 2005-07-13 |
3194
- | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3195
- | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3455
+ | 1 | Paul | 32 | California | 20000 | 2001-07-13 |
3456
+ | 3 | Teddy | 23 | Norway | 20000 | 2007-12-13 |
3457
+ | 4 | Mark | 25 | Rich-Mond | 65000 | 2007-12-13 |
3458
+ | 5 | David | 27 | Texas | 85000 | 2007-12-13 |
3459
+ | 2 | Allen | 25 | Texas | | 2005-07-13 |
3460
+ | 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
3461
+ | 9 | James | 44 | Norway | 5000 | 2005-07-13 |
3196
3462
  | 10 | James | 45 | Texas | 5000 | |
3197
- #+END_EXAMPLE
3463
+ #+end_example
3198
3464
 
3199
- And you can supply a block to them as well to specify formatting or footers:
3465
+ And you can supply a block to them to specify formatting or footers:
3200
3466
 
3201
- #+BEGIN_SRC ruby :wrap EXAMPLE
3467
+ #+BEGIN_SRC ruby
3202
3468
  tab_a.to_aoa do |f|
3203
- f.format(numeric: '0.0,R', id: '3.0C')
3469
+ f.format(numeric: '$0.0,R', id: '3.0C')
3204
3470
  f.sum_footer(:salary, :age)
3205
3471
  end
3206
3472
  #+END_SRC
3207
3473
 
3208
- #+BEGIN_EXAMPLE
3209
- | Id | Name | Age | Address | Salary | Join Date |
3210
- |-------+-------+-----+------------+---------+------------|
3211
- | 001 | Paul | 32 | California | 20,000 | 2001-07-13 |
3212
- | 003 | Teddy | 23 | Norway | 20,000 | 2007-12-13 |
3213
- | 004 | Mark | 25 | Rich-Mond | 65,000 | 2007-12-13 |
3214
- | 005 | David | 27 | Texas | 85,000 | 2007-12-13 |
3215
- | 002 | Allen | 25 | Texas | | 2005-07-13 |
3216
- | 008 | Paul | 24 | Houston | 20,000 | 2005-07-13 |
3217
- | 009 | James | 44 | Norway | 5,000 | 2005-07-13 |
3218
- | 010 | James | 45 | Texas | 5,000 | |
3219
- |-------+-------+-----+------------+---------+------------|
3220
- | Total | | 245 | | 220,000 | |
3221
- #+END_EXAMPLE
3474
+ #+RESULTS:
3475
+ #+begin_example
3476
+ | Id | Name | Age | Address | Salary | Join Date |
3477
+ |-------+-------+------+------------+----------+------------|
3478
+ | 001 | Paul | $32 | California | $20,000 | 2001-07-13 |
3479
+ | 003 | Teddy | $23 | Norway | $20,000 | 2007-12-13 |
3480
+ | 004 | Mark | $25 | Rich-Mond | $65,000 | 2007-12-13 |
3481
+ | 005 | David | $27 | Texas | $85,000 | 2007-12-13 |
3482
+ | 002 | Allen | $25 | Texas | | 2005-07-13 |
3483
+ | 008 | Paul | $24 | Houston | $20,000 | 2005-07-13 |
3484
+ | 009 | James | $44 | Norway | $5,000 | 2005-07-13 |
3485
+ | 010 | James | $45 | Texas | $5,000 | |
3486
+ |-------+-------+------+------------+----------+------------|
3487
+ | Total | | $245 | | $220,000 | |
3488
+ #+end_example
3222
3489
 
3223
3490
  * Development
3224
3491
  After checking out the repo, run `bin/setup` to install dependencies. Then, run