fat_table 0.2.7 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +7 -4
- data/.yardopts +5 -1
- data/Gemfile +2 -0
- data/README.org +82 -76
- data/README.rdoc +4 -4
- data/fat_table.gemspec +8 -8
- data/lib/fat_table.rb +14 -3
- data/lib/fat_table/column.rb +39 -27
- data/lib/fat_table/db_handle.rb +19 -47
- data/lib/fat_table/errors.rb +2 -0
- data/lib/fat_table/evaluator.rb +11 -5
- data/lib/fat_table/formatters.rb +2 -0
- data/lib/fat_table/formatters/aoa_formatter.rb +7 -5
- data/lib/fat_table/formatters/aoh_formatter.rb +8 -6
- data/lib/fat_table/formatters/formatter.rb +78 -61
- data/lib/fat_table/formatters/latex_formatter.rb +7 -5
- data/lib/fat_table/formatters/org_formatter.rb +5 -3
- data/lib/fat_table/formatters/term_formatter.rb +33 -28
- data/lib/fat_table/formatters/text_formatter.rb +5 -3
- data/lib/fat_table/patches.rb +5 -2
- data/lib/fat_table/table.rb +78 -57
- data/lib/fat_table/version.rb +3 -1
- data/{README.md → md/README.md} +5 -6
- metadata +49 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3cff489c9e921eff2138fb44b260b96d548819b7ee1479f9bf89675f2199c9ea
|
4
|
+
data.tar.gz: 7ad900e458b8d95baaf8044a4d25e742b1796ae9677d9f667180f034760e8a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 061ddacf0132d62f7d428f513c7a14277a4668c5a37148f80ef87dc484163ee4c001164e20a854d61761f21d6df025a700171e85c33e4f53c548014d7804b4e2
|
7
|
+
data.tar.gz: 11351e7a9c73624c4395960c226733b2c1ccaa126f0a0f1c2eee042b83f5adacbcea52e303b8566d5746c16648e202441d5df2216cc818799864600c7ee3bf69
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-shopify: rubocop.yml
|
3
|
+
require: rubocop-rspec
|
4
|
+
require: rubocop-performance
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 2.7
|
8
|
+
Exclude:
|
9
|
+
- 'test/tmp/**/*'
|
10
|
+
- 'vendor/bundle/**/*'
|
11
|
+
|
12
|
+
Style/MethodCallWithArgsParentheses:
|
13
|
+
Exclude:
|
14
|
+
- '**/Gemfile'
|
15
|
+
|
16
|
+
Style/ClassAndModuleChildren:
|
17
|
+
Exclude:
|
18
|
+
- 'test/**/*'
|
data/.travis.yml
CHANGED
@@ -2,8 +2,9 @@ language: ruby
|
|
2
2
|
before_install:
|
3
3
|
- sudo apt-get -qq update
|
4
4
|
- sudo apt-get install -y texlive-latex-base texlive-latex-recommended
|
5
|
-
|
6
|
-
|
5
|
+
- gem install pg
|
6
|
+
# before_script:
|
7
|
+
# - createdb -U travis travis
|
7
8
|
after_failure:
|
8
9
|
- "pwd"
|
9
10
|
- "cat ./spec/tmp/latex.err"
|
@@ -13,7 +14,9 @@ bundler_args: --without debug
|
|
13
14
|
services:
|
14
15
|
- postgresql
|
15
16
|
rvm:
|
16
|
-
- 2.2.2
|
17
|
-
- 2.3
|
18
17
|
- 2.4
|
18
|
+
- 2.5
|
19
|
+
- 2.6
|
20
|
+
- 2.7
|
19
21
|
- ruby-head
|
22
|
+
- truffleruby
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
data/README.org
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
#+LATEX_HEADER: \usepackage[margin=0.75in]{geometry}
|
3
3
|
|
4
4
|
#+BEGIN_COMMENT
|
5
|
+
This is for markdown output:
|
6
|
+
|
5
7
|
[![Build Status](https://travis-ci.org/ddoherty03/fat_table.svg?branch=master)](https://travis-ci.org/ddoherty03/fat_table)
|
8
|
+
|
9
|
+
The following is for org.
|
6
10
|
#+END_COMMENT
|
7
11
|
|
8
12
|
[[https://travis-ci.org/ddoherty03/fat_table.svg?branch=master]]
|
@@ -12,7 +16,7 @@
|
|
12
16
|
~FatTable~ is a gem that treats tables as a data type. It provides methods for
|
13
17
|
constructing tables from a variety of sources, building them row-by-row,
|
14
18
|
extracting rows, columns, and cells, and performing aggregate operations on
|
15
|
-
columns. It also provides
|
19
|
+
columns. It also provides a set of SQL-esque methods for manipulating table
|
16
20
|
objects: ~select~ for filtering by columns or for creating new columns, ~where~
|
17
21
|
for filtering by rows, ~order_by~ for sorting rows, ~distinct~ for eliminating
|
18
22
|
duplicate rows, ~group_by~ for aggregating multiple rows into single rows and
|
@@ -31,7 +35,7 @@ no-ops.
|
|
31
35
|
~FatTable~ can be used to perform operations on data that are naturally best
|
32
36
|
conceived of as tables, which in my experience is quite often. It can also serve
|
33
37
|
as a foundation for providing reporting functions where flexibility about the
|
34
|
-
output medium can be
|
38
|
+
output medium can be useful. Finally ~FatTable~ can be used within Emacs
|
35
39
|
~org-mode~ files in code blocks targeting the Ruby language. Org mode tables are
|
36
40
|
presented to a ruby code block as an array of arrays, so ~FatTable~ can read
|
37
41
|
them in with its ~.from_aoa~ constructor. A ~FatTable~ table output as an array
|
@@ -40,17 +44,6 @@ buffer as an org-table, ready for processing by other code blocks.
|
|
40
44
|
|
41
45
|
* Installation
|
42
46
|
|
43
|
-
** Prerequisites
|
44
|
-
The ~fat_table~ gem depends on several libraries being available for building,
|
45
|
-
mostly those concerned with accessing databases. On an ubuntu system, the
|
46
|
-
following packages should be installed before you install the ~fat_table~ gem:
|
47
|
-
|
48
|
-
- ruby-dev
|
49
|
-
- build-essential
|
50
|
-
- libsqlite3-dev
|
51
|
-
- libpq-dev
|
52
|
-
- libmysqlclient-dev
|
53
|
-
|
54
47
|
** Installing the gem
|
55
48
|
|
56
49
|
Add this line to your application's Gemfile:
|
@@ -76,7 +69,7 @@ Or install it yourself as:
|
|
76
69
|
|
77
70
|
~FatTable~ provides table objects as a data type that can be constructed and
|
78
71
|
operated on in a number of ways. Here's a quick example to illustrate the use of
|
79
|
-
|
72
|
+
~FatTable~. See the detailed explanations further on down.
|
80
73
|
|
81
74
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
82
75
|
#+BEGIN_SRC ruby
|
@@ -165,11 +158,12 @@ the main features of ~FatTable~. See the detailed explanations further on down.
|
|
165
158
|
|
166
159
|
** A Word About the Examples
|
167
160
|
|
168
|
-
When you install the ~fat_table~ gem, you have access to a program ~ft_console
|
161
|
+
When you install the ~fat_table~ gem, you have access to a program ~ft_console~,
|
169
162
|
which opens a ~pry~ session with ~fat_table~ loaded and the tables used in the
|
170
163
|
examples in this ~README~ defined as instance variables so you can experiment
|
171
164
|
with them. Because they are defined as instance variables, you have to write
|
172
|
-
~tab1~ as ~@tab1~ in ~ft_console~, but otherwise the examples should work
|
165
|
+
~tab1~ as ~@tab1~ in ~ft_console~, but otherwise the examples should work as
|
166
|
+
shown in this ~README~.
|
173
167
|
|
174
168
|
The examples in this ~README~ file are executed as code blocks within the
|
175
169
|
~README.org~ file, so they typically end with a call to ~.to_aoa~. That causes
|
@@ -231,7 +225,7 @@ locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_ lib str version
|
|
231
225
|
[4] pry(main)>
|
232
226
|
#+END_EXAMPLE
|
233
227
|
|
234
|
-
|
228
|
+
If you use ~puts table.to_term~, you can see the effect of the color formatting
|
235
229
|
directives.
|
236
230
|
|
237
231
|
** Anatomy of a Table
|
@@ -478,16 +472,16 @@ This example illustrates several things:
|
|
478
472
|
where the number of shares is greater than 500. More on that later.
|
479
473
|
4. ~FatTable~ passes back to org-mode an array of arrays using the ~.to_aoa~
|
480
474
|
method. In an ~org-mode~ buffer, these are rendered as tables. We'll often
|
481
|
-
apply ~.to_aoa~ at the end of example blocks to render the
|
482
|
-
this
|
483
|
-
to which formatting
|
475
|
+
apply ~.to_aoa~ at the end of example blocks in this ~README~ to render the
|
476
|
+
results as a table inside this file. As we'll see below, ~.to_aoa~ can also
|
477
|
+
take a block to which formatting and footer directives can be attached.
|
484
478
|
|
485
479
|
*** From Arrays of Hashes
|
486
480
|
|
487
481
|
A second ruby data structure that can be used to initialize a ~FatTable~ table
|
488
482
|
is an array of ruby Hashes. Each hash represents a row of the table, and the
|
489
|
-
headers of the table are
|
490
|
-
hashes
|
483
|
+
headers of the table are taken from the keys of the hashes. Accordingly, all the
|
484
|
+
hashes must have the same keys.
|
491
485
|
|
492
486
|
This same method can in fact take an array of any objects that can be converted
|
493
487
|
to a Hash with the ~#to_h~ method, so you can use an array of your own objects
|
@@ -517,40 +511,38 @@ tab = FatTable.from_aoh(aoh)
|
|
517
511
|
#+END_SRC
|
518
512
|
|
519
513
|
Notice, again, that the values can either be ruby objects, such as ~Date.today~,
|
520
|
-
or strings that can parsed into one of the permissible column types.
|
514
|
+
or strings that can be parsed into one of the permissible column types.
|
521
515
|
|
522
516
|
*** From SQL queries
|
523
517
|
|
524
|
-
Another way to initialize a ~FatTable~ table is with the results of a SQL
|
525
|
-
|
526
|
-
|
518
|
+
Another way to initialize a ~FatTable~ table is with the results of a SQL
|
519
|
+
query. Before you can connect to a database, you need to make sure that the required
|
520
|
+
adapter for your database is installed. ~FatTable~ uses the ~sequel~ gem
|
521
|
+
under the hood, so any database that it supports can be used. For example, if
|
522
|
+
you are accessing a Postgres database, you must install the ~pg~ gem with
|
523
|
+
|
524
|
+
#+begin_src sh
|
525
|
+
$ gem install pg
|
526
|
+
#+end_src
|
527
|
+
|
528
|
+
You must first set the database parameters to be used for the queries.
|
527
529
|
|
528
530
|
#+BEGIN_SRC ruby
|
529
531
|
# This automatically requires sequel.
|
530
532
|
require 'fat_table'
|
531
|
-
FatTable.
|
533
|
+
FatTable.connect(adapter: 'postgres',
|
532
534
|
database: 'XXX_development',
|
533
|
-
user: '
|
534
|
-
password: '
|
535
|
-
host: '
|
536
|
-
socket: '/tmp/.s.PGSQL.5432')
|
535
|
+
user: 'ken',
|
536
|
+
password: 'imsecret',
|
537
|
+
host: 'db.lan')
|
537
538
|
tab = FatTable.from_sql('select * from trades;')
|
538
539
|
#+END_SRC
|
539
540
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
is required.
|
546
|
-
|
547
|
-
The ~.set_db~ function need only be called once, and the database handle it
|
548
|
-
creates will be used for all subsequent ~.from_sql~ calls until ~.set_db~ is
|
549
|
-
called again.
|
550
|
-
|
551
|
-
Alternatively, you can build the ~Sequel~ connection with ~Sequel.connect~ or
|
552
|
-
with adapter-specific ~Sequel~ connection methods and let ~FatTable~ know to use
|
553
|
-
that connection:
|
541
|
+
The arguments to ~connect~ are simply passed on to ~sequel~'s connect method, so
|
542
|
+
any set of arguments that work for it should work for ~connect~. Alternatively,
|
543
|
+
you can build the ~Sequel~ connection directly with ~Sequel.connect~ or with
|
544
|
+
adapter-specific ~Sequel~ connection methods and let ~FatTable~ know to use that
|
545
|
+
connection:
|
554
546
|
|
555
547
|
#+BEGIN_SRC ruby
|
556
548
|
require 'fat_table'
|
@@ -561,8 +553,15 @@ that connection:
|
|
561
553
|
Consult ~Sequel's~ documentation for details on its connection methods.
|
562
554
|
[[http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html]]
|
563
555
|
|
556
|
+
The ~.connect~ function need only be called once, and the database handle it
|
557
|
+
creates will be used for all subsequent ~.from_sql~ calls until ~.connect~ is
|
558
|
+
called again.
|
559
|
+
|
564
560
|
*** Marking Groups in Input
|
565
561
|
|
562
|
+
~FatTable~ tables has a concept of "groups" of rows that play a role in many of
|
563
|
+
the methods for operating on them as explained [[Groups][below]].
|
564
|
+
|
566
565
|
The ~.from_aoa~ and ~.from_aoh~ functions take an optional keyword parameter
|
567
566
|
~hlines:~ that, if set to ~true~, causes them to mark group boundaries in the
|
568
567
|
table wherever a row Array (for ~.from_aoa~) or Hash (for ~.from_aoh~) is
|
@@ -582,6 +581,7 @@ beginning with something like '~|---~'. The ~.from_org_...~ functions always
|
|
582
581
|
recognizes hlines in the input, so it takes no ~hlines:~ keyword parameter.
|
583
582
|
|
584
583
|
** Accessing Parts of Tables
|
584
|
+
|
585
585
|
*** Rows
|
586
586
|
|
587
587
|
A ~FatTable~ table is an Enumerable, yielding each row of the table as a Hash
|
@@ -637,6 +637,7 @@ operation, which mutates the receiver table by removing its group boundaries.
|
|
637
637
|
Second, because each operation returns a ~FatTable::Table~ object, the
|
638
638
|
operations are chainable.
|
639
639
|
|
640
|
+
<<Groups>>
|
640
641
|
Third, ~FatTable::Table~ objects can have "groups" of rows within the table.
|
641
642
|
These can be decorated with hlines and group footers on output. Some of these
|
642
643
|
operations result in marking group boundaries in the result table, others remove
|
@@ -767,17 +768,18 @@ symbol representing an existing column, which has the effect of renaming an
|
|
767
768
|
existing column, or (2) a string representing a ruby expression for the value of
|
768
769
|
a new column.
|
769
770
|
|
770
|
-
Within the string expression, the names of existing or already-specified
|
771
|
-
are available as local variables
|
772
|
-
'@
|
773
|
-
|
771
|
+
Within the string expression, the names of existing or already-specified
|
772
|
+
columns are available as local variables. In addition the instance variables
|
773
|
+
'@row' and '@group' are available as the row number and group number of the
|
774
|
+
new value. So for our example table, the string expressions for new columns
|
775
|
+
have access to local variables ~ref~, ~date~, ~code~, ~price~, ~g10~, ~qp10~,
|
774
776
|
~shares~, ~lp~, ~qp~, ~iplp~, and ~ipqp~ as well as the instance variables
|
775
777
|
~@row~ and ~@group~. The local variables are set to the values of the cell in
|
776
|
-
their respective columns for each row in the input table and the instance
|
777
|
-
variables are set the number of the current row and group respectively.
|
778
|
+
their respective columns for each row in the input table, and the instance
|
779
|
+
variables are set the number of the current row and group number respectively.
|
778
780
|
|
779
|
-
For example, if we want to rename the ~:date~
|
780
|
-
compute the cost of shares, we could do the following:
|
781
|
+
For example, if we want to rename the ~traded_on~ column to ~:date~ and add a
|
782
|
+
new column to compute the cost of shares, we could do the following:
|
781
783
|
|
782
784
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
783
785
|
#+BEGIN_SRC ruby
|
@@ -959,28 +961,21 @@ You can sort a table on any number of columns with ~order_by~. The ~order_by~
|
|
959
961
|
method takes any number of symbol arguments for the columns to sort on. If you
|
960
962
|
specify more than one column, the sort is performed on the first column, then
|
961
963
|
all columns that are equal with respect to the first column are sorted by the
|
962
|
-
second column, and so on.
|
963
|
-
|
964
|
+
second column, and so on. Ordering is done is ascending order for each of the
|
965
|
+
columns, but can be reversed by adding a '!' to the end a symbol argument.
|
966
|
+
All columns of the input table are included in the output.
|
964
967
|
|
965
|
-
Let's sort our table first by ~:code~, then
|
968
|
+
Let's sort our table first by ~:code~, then in reverse order of ~:date~.
|
966
969
|
|
967
970
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
968
971
|
#+BEGIN_SRC ruby
|
969
|
-
tab1.order_by(:code, :date) \
|
972
|
+
tab1.order_by(:code, :date!) \
|
970
973
|
.to_aoa
|
971
974
|
#+END_SRC
|
972
975
|
|
973
|
-
#+
|
976
|
+
#+begin_EXAMPLE
|
974
977
|
| Ref | Date | Code | Price | G10 | QP10 | Shares | Lp | Qp | Iplp | Ipqp |
|
975
978
|
|------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
|
976
|
-
| T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
977
|
-
| T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
978
|
-
| T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
979
|
-
| T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
980
|
-
| T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
|
981
|
-
| T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
|
982
|
-
| T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
|
983
|
-
|------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
|
984
979
|
| T011 | 2016-11-02 | P | 7.425 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
985
980
|
| T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
986
981
|
| T012 | 2016-11-02 | P | 7.55 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
@@ -989,12 +984,20 @@ Let's sort our table first by ~:code~, then by ~:date~.
|
|
989
984
|
| T015 | 2016-11-02 | P | 7.75 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
990
985
|
| T016 | 2016-11-02 | P | 8.25 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
991
986
|
|------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
|
987
|
+
| T001 | 2016-11-01 | P | 7.7 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
988
|
+
| T002 | 2016-11-01 | P | 7.75 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
989
|
+
| T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
990
|
+
| T003 | 2016-11-01 | P | 7.5 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
991
|
+
| T008 | 2016-11-01 | P | 7.65 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
|
992
|
+
| T009 | 2016-11-01 | P | 7.6 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
|
993
|
+
| T010 | 2016-11-01 | P | 7.55 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
|
994
|
+
|------+------------+------+-------+-----+------+--------+------+-------+--------+--------|
|
992
995
|
| T004 | 2016-11-01 | S | 7.55 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
|
993
996
|
| T005 | 2016-11-01 | S | 7.5 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
|
994
997
|
| T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
995
998
|
| T006 | 2016-11-01 | S | 7.6 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
996
999
|
| T007 | 2016-11-01 | S | 7.65 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
997
|
-
#+
|
1000
|
+
#+end_EXAMPLE
|
998
1001
|
|
999
1002
|
The interesting thing about ~order_by~ is that, while it ignores groups in its
|
1000
1003
|
input, it adds group boundaries in the output table at those rows where the sort
|
@@ -1039,8 +1042,10 @@ the value is a symbol for one of several aggregating methods that
|
|
1039
1042
|
to the :price column so that the output shows the average price in each group.
|
1040
1043
|
The ~:shares~, ~:lp~, and ~:qp~ columns are summed, and the ~:any?~ aggregate is
|
1041
1044
|
applied to one of the boolean fields, that is, it is ~true~ if any of the values
|
1042
|
-
in that column are ~true~.
|
1043
|
-
|
1045
|
+
in that column are ~true~.
|
1046
|
+
|
1047
|
+
Note that the column names in the output of the aggregated columns have the
|
1048
|
+
name of the aggregating method pre-pended to the column name.
|
1044
1049
|
|
1045
1050
|
Here is a list of all the aggregate methods available. If the description
|
1046
1051
|
restricts the aggregate to particular column types, applying it to other types
|
@@ -1309,6 +1314,7 @@ table where the join expression is satisfied and augmented with nils otherwise.
|
|
1309
1314
|
Finally, a cross join outputs every row of ~tab_a~ augmented with every row of
|
1310
1315
|
~tab_b~, in other words, the Cartesian product of the two tables. If ~tab_a~ has
|
1311
1316
|
~N~ rows and ~tab_b~ has ~M~ rows, the output table will have ~N * M~ rows.
|
1317
|
+
So be careful lest you consume all your computer's memory.
|
1312
1318
|
|
1313
1319
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
1314
1320
|
#+BEGIN_SRC ruby
|
@@ -1346,10 +1352,10 @@ Finally, a cross join outputs every row of ~tab_a~ augmented with every row of
|
|
1346
1352
|
|
1347
1353
|
*** Set Operations
|
1348
1354
|
|
1349
|
-
~FatTable~ can perform several set operations on tables. In order for
|
1350
|
-
to be used this way, they must have the same number of columns with
|
1351
|
-
types or an exception will be raised. We'll call two tables that
|
1352
|
-
combining with set operations "set-compatible."
|
1355
|
+
~FatTable~ can perform several set operations on pairs of tables. In order for
|
1356
|
+
two tables to be used this way, they must have the same number of columns with
|
1357
|
+
the same types or an exception will be raised. We'll call two tables that
|
1358
|
+
qualify for combining with set operations "set-compatible."
|
1353
1359
|
|
1354
1360
|
We'll use the following two set-compatible tables in the examples. They each
|
1355
1361
|
have some duplicates and some group boundaries so you can see the effect of the
|
@@ -1761,9 +1767,9 @@ but ruby data structures, and for them, things such as alignment are irrelevant.
|
|
1761
1767
|
array of array,
|
1762
1768
|
|
1763
1769
|
These are all implemented by classes that inherit from ~FatTable::Formatter~
|
1764
|
-
class by defining about a dozen methods that get called at various places
|
1765
|
-
the construction of the output table. The idea is that more
|
1766
|
-
defined by adding additional classes.
|
1770
|
+
class by defining about a dozen methods that get called at various places
|
1771
|
+
during the construction of the output table. The idea is that more output
|
1772
|
+
formats can be defined by adding additional classes.
|
1767
1773
|
|
1768
1774
|
*** Table Locations
|
1769
1775
|
|
data/README.rdoc
CHANGED
@@ -485,7 +485,7 @@ Another way to initialize a +FatTable+ table is with the results of a SQL query.
|
|
485
485
|
database parameters to be used for the queries.
|
486
486
|
|
487
487
|
require 'fat_table'
|
488
|
-
FatTable.
|
488
|
+
FatTable.connect(driver: 'Pg',
|
489
489
|
database: 'XXX_development',
|
490
490
|
user: 'dtd',
|
491
491
|
password: 'slflpowert',
|
@@ -493,15 +493,15 @@ database parameters to be used for the queries.
|
|
493
493
|
socket: '/tmp/.s.PGSQL.5432')
|
494
494
|
tab = FatTable.from_sql('select * from trades;')
|
495
495
|
|
496
|
-
Some of the parameters to the +.
|
496
|
+
Some of the parameters to the +.connect+ function have defaults. The driver
|
497
497
|
defaults to 'Pg' for postgresql and the socket defaults to +/tmp/.s.PGSQL.5432+
|
498
498
|
if the host is 'localhost', which it is by default. If the host is not
|
499
499
|
'localhost', the dsn uses a port rather than a socket and defaults to port
|
500
500
|
'5432'. While user and password default to nil, the database parameter is
|
501
501
|
required.
|
502
502
|
|
503
|
-
The +.
|
504
|
-
creates will be used for all subsequent +.from_sql+ calls until +.
|
503
|
+
The +.connect+ function need only be called once, and the database handle it
|
504
|
+
creates will be used for all subsequent +.from_sql+ calls until +.connect+ is
|
505
505
|
called again.
|
506
506
|
|
507
507
|
=== Marking Groups in Input
|
data/fat_table.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
lib = File.expand_path('../lib', __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'fat_table/version'
|
4
|
-
require 'fat_table/patches'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = 'fat_table'
|
@@ -10,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
10
9
|
spec.email = ['ded-law@ddoherty.net']
|
11
10
|
|
12
11
|
spec.summary = 'Provides tools for working with tables as a data type.'
|
13
|
-
spec.description = <<-DESC
|
12
|
+
spec.description = <<-DESC
|
14
13
|
FatTable is a gem that treats tables as a data type. It provides methods for
|
15
14
|
constructing tables from a variety of sources, building them row-by-row,
|
16
15
|
extracting rows, columns, and cells, and performing aggregate operations on
|
@@ -64,21 +63,22 @@ Gem::Specification.new do |spec|
|
|
64
63
|
spec.require_paths = ['lib']
|
65
64
|
spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
|
66
65
|
|
67
|
-
spec.add_development_dependency 'bundler'
|
66
|
+
spec.add_development_dependency 'bundler'
|
68
67
|
spec.add_development_dependency 'byebug'
|
69
68
|
spec.add_development_dependency 'pry'
|
70
69
|
spec.add_development_dependency 'pry-byebug'
|
71
70
|
spec.add_development_dependency 'pry-doc'
|
72
|
-
spec.add_development_dependency '
|
71
|
+
spec.add_development_dependency 'ruby_jard'
|
72
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
73
73
|
spec.add_development_dependency 'redcarpet'
|
74
74
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
75
|
+
spec.add_development_dependency 'rubocop-rspec'
|
76
|
+
spec.add_development_dependency 'rubocop-performance'
|
75
77
|
spec.add_development_dependency 'simplecov'
|
76
78
|
|
77
79
|
spec.add_runtime_dependency 'activesupport', '>3.0'
|
78
|
-
spec.add_runtime_dependency 'fat_core', '
|
79
|
-
spec.add_runtime_dependency 'mysql2'
|
80
|
-
spec.add_runtime_dependency 'pg'
|
80
|
+
spec.add_runtime_dependency 'fat_core', '>= 4.1'
|
81
81
|
spec.add_runtime_dependency 'rainbow'
|
82
82
|
spec.add_runtime_dependency 'sequel'
|
83
|
-
spec.add_runtime_dependency '
|
83
|
+
spec.add_runtime_dependency 'gem-path'
|
84
84
|
end
|