fat_table 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/README.md +2168 -0
- data/README.org +230 -212
- data/TODO.org +7 -0
- data/bin/ft_console +82 -79
- data/fat_table.gemspec +45 -43
- data/lib/fat_table.rb +1 -1
- data/lib/fat_table/column.rb +31 -22
- data/lib/fat_table/db_handle.rb +61 -50
- data/lib/fat_table/evaluator.rb +20 -22
- data/lib/fat_table/formatters/aoa_formatter.rb +1 -2
- data/lib/fat_table/formatters/aoh_formatter.rb +1 -2
- data/lib/fat_table/formatters/formatter.rb +38 -33
- data/lib/fat_table/formatters/latex_formatter.rb +2 -2
- data/lib/fat_table/formatters/org_formatter.rb +5 -6
- data/lib/fat_table/formatters/term_formatter.rb +3 -5
- data/lib/fat_table/formatters/text_formatter.rb +3 -4
- data/lib/fat_table/patches.rb +29 -1
- data/lib/fat_table/table.rb +81 -77
- data/lib/fat_table/version.rb +1 -1
- metadata +80 -82
data/TODO.org
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
* DONE Ensure that columns resulting from aggregates have proper type
|
2
|
+
CLOSED: [2017-12-29 Fri 05:34]
|
3
|
+
- State "WAIT" from "TODO" [2017-12-29 Fri 05:34]
|
4
|
+
- State "TODO" from [2017-11-27 Mon 04:46]
|
5
|
+
After applying avg, does the column have the proper Numeric or Date, or DateTime
|
6
|
+
type. How about Boolean aggregates?
|
7
|
+
|
1
8
|
* TODO Conversion to Spreadsheets
|
2
9
|
- State "TODO" from [2017-04-21 Fri 10:36]
|
3
10
|
This is a [[https://github.com/westonganger/spreadsheet_architect][gem]] that I can include into the Table model to convert a table into
|
data/bin/ft_console
CHANGED
@@ -4,22 +4,23 @@ require 'bundler/setup'
|
|
4
4
|
require 'fat_table'
|
5
5
|
require 'pry'
|
6
6
|
|
7
|
-
@data =
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
@data = [
|
8
|
+
%w[Date Code Raw Shares Price Info Ok],
|
9
|
+
['2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'ENTITY3', 'F'],
|
10
|
+
['2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'ENTITY1', 'T'],
|
11
|
+
['2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'ENTITY3', 'F'],
|
12
|
+
['2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', 'T'],
|
13
|
+
['2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'ENTITY3', 'T'],
|
14
|
+
['2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'ENTITY3', 'T'],
|
15
|
+
['2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'ENTITY1', 'T'],
|
16
|
+
['2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'ENTITY3', 'T'],
|
17
|
+
['2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'ENTITY3', 'T'],
|
18
|
+
['2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'ENTITY3', 'T'],
|
19
|
+
['2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'ENTITY3', 'T'],
|
20
|
+
['2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'ENTITY3', 'F']
|
21
|
+
]
|
21
22
|
|
22
|
-
@tab_a_str =
|
23
|
+
@tab_a_str = <<~TABLE
|
23
24
|
| Id | Name | Age | Address | Salary | Join Date |
|
24
25
|
|----+-------+-----+------------+--------+------------|
|
25
26
|
| 1 | Paul | 32 | California | 20000 | 2001-07-13 |
|
@@ -30,85 +31,87 @@ require 'pry'
|
|
30
31
|
| 8 | Paul | 24 | Houston | 20000 | 2005-07-13 |
|
31
32
|
| 9 | James | 44 | Norway | 5000 | 2005-07-13 |
|
32
33
|
| 10 | James | 45 | Texas | 5000 | |
|
33
|
-
|
34
|
+
TABLE
|
34
35
|
|
35
|
-
@tab_b_str =
|
36
|
+
@tab_b_str = <<~TABLE
|
36
37
|
| Id | Dept | Emp Id |
|
37
38
|
|----+-------------+--------|
|
38
39
|
| 1 | IT Billing | 1 |
|
39
40
|
| 2 | Engineering | 2 |
|
40
41
|
| 3 | Finance | 7 |
|
41
|
-
|
42
|
+
TABLE
|
42
43
|
|
43
44
|
@tab_a = FatTable.from_org_string(@tab_a_str)
|
44
45
|
@tab_b = FatTable.from_org_string(@tab_b_str)
|
45
46
|
|
46
|
-
@tab1_str =
|
47
|
-
| Ref | Date | Code | Price | G10 | QP10 | Shares | LP | QP | IPLP | IPQP |
|
48
|
-
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
49
|
-
| T001 | [2016-11-01 Tue] | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
50
|
-
| T002 | [2016-11-01 Tue] | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
51
|
-
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
52
|
-
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
53
|
-
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
54
|
-
| T004 | [2016-11-01 Tue] | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
|
55
|
-
| T005 | [2016-11-01 Tue] | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
|
56
|
-
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
57
|
-
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
58
|
-
| T007 | [2016-11-01 Tue] | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
59
|
-
| T008 | [2016-11-01 Tue] | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
|
60
|
-
| T009 | [2016-11-01 Tue] | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
|
61
|
-
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
62
|
-
| T010 | [2016-11-01 Tue] | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
|
63
|
-
| T011 | [2016-11-02 Wed] | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
64
|
-
| T012 | [2016-11-02 Wed] | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
65
|
-
| T012 | [2016-11-02 Wed] | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
66
|
-
| T013 | [2016-11-02 Wed] | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
|
67
|
-
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
68
|
-
| T014 | [2016-11-02 Wed] | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
|
69
|
-
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
70
|
-
| T016 | [2016-11-02 Wed] | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
71
|
-
|
47
|
+
@tab1_str = <<~TABLE
|
48
|
+
| Ref | Date | Code | Price | G10 | QP10 | Shares | LP | QP | IPLP | IPQP |
|
49
|
+
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
50
|
+
| T001 | [2016-11-01 Tue] | P | 7.7000 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
51
|
+
| T002 | [2016-11-01 Tue] | P | 7.7500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
52
|
+
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
53
|
+
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
54
|
+
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
55
|
+
| T004 | [2016-11-01 Tue] | S | 7.5500 | T | F | 6811 | 966 | 5845 | 0.2453 | 0.1924 |
|
56
|
+
| T005 | [2016-11-01 Tue] | S | 7.5000 | F | F | 4000 | 572 | 3428 | 0.2453 | 0.1924 |
|
57
|
+
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
58
|
+
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
59
|
+
| T007 | [2016-11-01 Tue] | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
60
|
+
| T008 | [2016-11-01 Tue] | P | 7.6500 | F | F | 2771 | 393 | 2378 | 0.2453 | 0.1924 |
|
61
|
+
| T009 | [2016-11-01 Tue] | P | 7.6000 | F | F | 9550 | 1363 | 8187 | 0.2453 | 0.1924 |
|
62
|
+
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
63
|
+
| T010 | [2016-11-01 Tue] | P | 7.5500 | F | T | 3175 | 451 | 2724 | 0.2453 | 0.1924 |
|
64
|
+
| T011 | [2016-11-02 Wed] | P | 7.4250 | T | F | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
65
|
+
| T012 | [2016-11-02 Wed] | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
66
|
+
| T012 | [2016-11-02 Wed] | P | 7.5500 | F | F | 4700 | 677 | 4023 | 0.2453 | 0.1924 |
|
67
|
+
| T013 | [2016-11-02 Wed] | P | 7.3500 | T | T | 53100 | 7656 | 45444 | 0.2453 | 0.1924 |
|
68
|
+
|------+------------------+------+--------+-----+------+--------+------+-------+--------+--------|
|
69
|
+
| T014 | [2016-11-02 Wed] | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
|
70
|
+
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
71
|
+
| T016 | [2016-11-02 Wed] | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
72
|
+
TABLE
|
72
73
|
|
73
|
-
@tab2_str =
|
74
|
-
| Ref | Date | Code | Price | G10 | QP10 | Shares | LP | QP | IPLP | IPQP |
|
75
|
-
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
76
|
-
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
77
|
-
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
78
|
-
| T017 | [2016-11-01 Tue] | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
|
79
|
-
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
80
|
-
| T018 | [2016-11-01 Tue] | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
|
81
|
-
| T018 | [2016-11-01 Tue] | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
|
82
|
-
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
83
|
-
| T007 | [2016-11-01 Tue] | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
84
|
-
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
85
|
-
| T014 | [2016-11-02 Wed] | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
|
86
|
-
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
87
|
-
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
88
|
-
| T016 | [2016-11-02 Wed] | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
89
|
-
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
90
|
-
| T019 | [2017-01-15 Sun] | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
|
91
|
-
| T020 | [2017-01-19 Thu] | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
|
92
|
-
| T021 | [2017-01-23 Mon] | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
|
93
|
-
| T021 | [2017-01-23 Mon] | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
|
94
|
-
|
74
|
+
@tab2_str = <<~TABLE
|
75
|
+
| Ref | Date | Code | Price | G10 | QP10 | Shares | LP | QP | IPLP | IPQP |
|
76
|
+
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
77
|
+
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
78
|
+
| T003 | [2016-11-01 Tue] | P | 7.5000 | F | T | 800 | 112 | 688 | 0.2453 | 0.1924 |
|
79
|
+
| T017 | [2016-11-01 Tue] | P | 8.3 | F | T | 1801 | 1201 | 600 | 0.2453 | 0.1924 |
|
80
|
+
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
81
|
+
| T018 | [2016-11-01 Tue] | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
|
82
|
+
| T018 | [2016-11-01 Tue] | S | 7.152 | T | F | 2516 | 2400 | 116 | 0.2453 | 0.1924 |
|
83
|
+
| T006 | [2016-11-01 Tue] | S | 7.6000 | F | T | 1000 | 143 | 857 | 0.2453 | 0.1924 |
|
84
|
+
| T007 | [2016-11-01 Tue] | S | 7.6500 | T | F | 200 | 28 | 172 | 0.2453 | 0.1924 |
|
85
|
+
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
86
|
+
| T014 | [2016-11-02 Wed] | P | 7.4500 | F | T | 5847 | 835 | 5012 | 0.2453 | 0.1924 |
|
87
|
+
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
88
|
+
| T015 | [2016-11-02 Wed] | P | 7.7500 | F | F | 500 | 72 | 428 | 0.2453 | 0.1924 |
|
89
|
+
| T016 | [2016-11-02 Wed] | P | 8.2500 | T | T | 100 | 14 | 86 | 0.2453 | 0.1924 |
|
90
|
+
|------+------------------+------+--------+-----+------+--------+-------+------+--------+--------|
|
91
|
+
| T019 | [2017-01-15 Sun] | S | 8.75 | T | F | 300 | 175 | 125 | 0.2453 | 0.1924 |
|
92
|
+
| T020 | [2017-01-19 Thu] | S | 8.25 | F | T | 700 | 615 | 85 | 0.2453 | 0.1924 |
|
93
|
+
| T021 | [2017-01-23 Mon] | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
|
94
|
+
| T021 | [2017-01-23 Mon] | P | 7.16 | T | T | 12100 | 11050 | 1050 | 0.2453 | 0.1924 |
|
95
|
+
TABLE
|
95
96
|
|
96
97
|
@tab1 = FatTable.from_org_string(@tab1_str)
|
97
98
|
@tab2 = FatTable.from_org_string(@tab2_str)
|
98
99
|
|
99
|
-
@aoa = [
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
100
|
+
@aoa = [
|
101
|
+
%w[Ref Date Code Raw Shares Price Info Bool],
|
102
|
+
[1, '2013-05-02', 'P', 795_546.20, 795_546.2, 1.1850, 'YLPEF1', 'T'],
|
103
|
+
[2, '2013-05-02', 'P', 118_186.40, 118_186.4, 11.8500, 'YLPEF1', 'T'],
|
104
|
+
[7, '2013-05-20', 'S', 12_000.00, 5046.00, 28.2804, 'YLEAC', 'F'],
|
105
|
+
[8, '2013-05-20', 'S', 85_000.00, 35_742.50, 28.3224, 'YLEAC', 'T'],
|
106
|
+
[9, '2013-05-20', 'S', 33_302.00, 14_003.49, 28.6383, 'YLEAC', 'T'],
|
107
|
+
[10, '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'YLEAC', 'T'],
|
108
|
+
[11, '2013-05-23', 'S', 23_054.00, 9694.21, 26.8015, 'YLEAC', 'F'],
|
109
|
+
[12, '2013-05-23', 'S', 39_906.00, 16_780.47, 25.1749, 'YLEAC', 'T'],
|
110
|
+
[13, '2013-05-29', 'S', 13_459.00, 5659.51, 24.7464, 'YLEAC', 'T'],
|
111
|
+
[14, '2013-05-29', 'S', 15_700.00, 6601.85, 24.7790, 'YLEAC', 'F'],
|
112
|
+
[15, '2013-05-29', 'S', 15_900.00, 6685.95, 24.5802, 'YLEAC', 'T'],
|
113
|
+
[16, '2013-05-30', 'S', 6_679.00, 2808.52, 25.0471, 'YLEAC', 'T']
|
114
|
+
]
|
112
115
|
@tt = FatTable.from_aoa(@aoa)
|
113
116
|
|
114
117
|
Pry.start
|
data/fat_table.gemspec
CHANGED
@@ -1,48 +1,50 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
lib = File.expand_path('../lib', __FILE__)
|
4
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
require 'fat_table/version'
|
4
|
+
require 'fat_table/patches'
|
6
5
|
|
7
6
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
7
|
+
spec.name = 'fat_table'
|
9
8
|
spec.version = FatTable::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
9
|
+
spec.authors = ['Daniel E. Doherty']
|
10
|
+
spec.email = ['ded-law@ddoherty.net']
|
11
|
+
|
12
|
+
spec.summary = 'Provides tools for working with tables as a data type.'
|
13
|
+
spec.description = <<-DESC.strip_heredoc
|
14
|
+
FatTable is a gem that treats tables as a data type. It provides methods for
|
15
|
+
constructing tables from a variety of sources, building them row-by-row,
|
16
|
+
extracting rows, columns, and cells, and performing aggregate operations on
|
17
|
+
columns. It also provides as set of SQL-esque methods for manipulating table
|
18
|
+
objects: select for filtering by columns or for creating new columns, where
|
19
|
+
for filtering by rows, order_by for sorting rows, distinct for eliminating
|
20
|
+
duplicate rows, group_by for aggregating multiple rows into single rows and
|
21
|
+
applying column aggregate methods to ungrouped columns, a collection of join
|
22
|
+
methods for combining tables, and more.
|
12
23
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
duplicate rows, group_by for aggregating multiple rows into single rows and
|
22
|
-
applying column aggregate methods to ungrouped columns, a collection of join
|
23
|
-
methods for combining tables, and more.
|
24
|
+
Furthermore, FatTable provides methods for formatting tables and producing
|
25
|
+
output that targets various output media: text, ANSI terminals, ruby data
|
26
|
+
structures, LaTeX tables, Emacs org-mode tables, and more. The formatting
|
27
|
+
methods can specify cell formatting in a way that is uniform across all the
|
28
|
+
output methods and can also decorate the output with any number of footers,
|
29
|
+
including group footers. FatTable applies formatting directives to the extent
|
30
|
+
they makes sense for the output medium and treats other formatting directives as
|
31
|
+
no-ops.
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
FatTable can be used to perform operations on data that are naturally best
|
34
|
+
conceived of as tables, which in my experience is quite often. It can also serve
|
35
|
+
as a foundation for providing reporting functions where flexibility about the
|
36
|
+
output medium can be quite useful. Finally FatTable can be used within Emacs
|
37
|
+
org-mode files in code blocks targeting the Ruby language. Org mode tables are
|
38
|
+
presented to a ruby code block as an array of arrays, so FatTable can read
|
39
|
+
them in with its .from_aoa constructor. A FatTable table can output as an
|
40
|
+
array of arrays with its .to_aoa output function and will be rendered in an
|
41
|
+
org-mode buffer as an org-table, ready for processing by other code blocks.
|
42
|
+
DESC
|
33
43
|
|
34
|
-
|
35
|
-
conceived of as tables, which in my experience is quite often. It can also serve
|
36
|
-
as a foundation for providing reporting functions where flexibility about the
|
37
|
-
output medium can be quite useful. Finally FatTable can be used within Emacs
|
38
|
-
org-mode files in code blocks targeting the Ruby language. Org mode tables are
|
39
|
-
presented to a ruby code block as an array of arrays, so FatTable can read
|
40
|
-
them in with its .from_aoa constructor. A FatTable table can output as an
|
41
|
-
array of arrays with its .to_aoa output function and will be rendered in an
|
42
|
-
org-mode buffer as an org-table, ready for processing by other code blocks.
|
43
|
-
}
|
44
|
+
spec.homepage = 'https://github.com/ddoherty03/fat_table'
|
44
45
|
|
45
|
-
|
46
|
+
# Use of squiggle heredocs knocks out older versions.
|
47
|
+
spec.required_ruby_version = '>= 2.2.2'
|
46
48
|
|
47
49
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
48
50
|
# 'allowed_push_host' to allow pushing to a single host or delete this section
|
@@ -54,7 +56,7 @@ org-mode buffer as an org-table, ready for processing by other code blocks.
|
|
54
56
|
'public gem pushes.'
|
55
57
|
end
|
56
58
|
|
57
|
-
spec.files
|
59
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
58
60
|
f.match(%r{^(test|spec|features)/})
|
59
61
|
end
|
60
62
|
spec.bindir = 'bin'
|
@@ -62,21 +64,21 @@ org-mode buffer as an org-table, ready for processing by other code blocks.
|
|
62
64
|
spec.require_paths = ['lib']
|
63
65
|
spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
|
64
66
|
|
65
|
-
spec.add_development_dependency 'simplecov'
|
66
67
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
67
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
68
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
69
68
|
spec.add_development_dependency 'byebug'
|
70
69
|
spec.add_development_dependency 'pry'
|
71
|
-
spec.add_development_dependency 'pry-doc'
|
72
70
|
spec.add_development_dependency 'pry-byebug'
|
71
|
+
spec.add_development_dependency 'pry-doc'
|
72
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
73
73
|
spec.add_development_dependency 'redcarpet'
|
74
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
75
|
+
spec.add_development_dependency 'simplecov'
|
74
76
|
|
77
|
+
spec.add_runtime_dependency 'activesupport', '>3.0'
|
75
78
|
spec.add_runtime_dependency 'fat_core', '~> 4.0', '>= 4.1'
|
76
|
-
spec.add_runtime_dependency '
|
79
|
+
spec.add_runtime_dependency 'mysql2'
|
80
|
+
spec.add_runtime_dependency 'pg'
|
77
81
|
spec.add_runtime_dependency 'rainbow'
|
78
82
|
spec.add_runtime_dependency 'sequel'
|
79
|
-
spec.add_runtime_dependency 'pg'
|
80
83
|
spec.add_runtime_dependency 'sqlite3'
|
81
|
-
spec.add_runtime_dependency 'mysql2'
|
82
84
|
end
|
data/lib/fat_table.rb
CHANGED
@@ -25,7 +25,7 @@ module FatTable
|
|
25
25
|
require 'fat_table/errors'
|
26
26
|
|
27
27
|
# Valid output formats as symbols.
|
28
|
-
FORMATS = [
|
28
|
+
FORMATS = %i[psv aoa aoh latex org term text].freeze
|
29
29
|
|
30
30
|
class << self
|
31
31
|
# Set a default output format to use when FatTable.to_format is invoked.
|
data/lib/fat_table/column.rb
CHANGED
@@ -28,7 +28,7 @@ module FatTable
|
|
28
28
|
attr_reader :items
|
29
29
|
|
30
30
|
# Valid Column types as strings.
|
31
|
-
TYPES = %w
|
31
|
+
TYPES = %w[NilClass Boolean DateTime Numeric String].freeze
|
32
32
|
|
33
33
|
# :category: Constructors
|
34
34
|
|
@@ -36,8 +36,8 @@ module FatTable
|
|
36
36
|
# +items+, as an array of either strings or ruby objects that are one of the
|
37
37
|
# permissible types or strings parsable as one of the permissible types. If
|
38
38
|
# no +items+ are passed, returns an empty Column to which items may be added
|
39
|
-
# with the Column#<< method. The item types must be one of the following
|
40
|
-
# strings parseable as one of them:
|
39
|
+
# with the Column#<< method. The item types must be one of the following
|
40
|
+
# types or strings parseable as one of them:
|
41
41
|
#
|
42
42
|
# Boolean::
|
43
43
|
# an object of type TrueClass or FalseClass or a string that is either
|
@@ -48,9 +48,8 @@ module FatTable
|
|
48
48
|
# an object of class Date, DateTime, or a string that matches
|
49
49
|
# +/\d\d\d\d[-\/]\d\d?[-\/]\d\d?/+ and is parseable by DateTime.parse.
|
50
50
|
#
|
51
|
-
# Numeric::
|
52
|
-
#
|
53
|
-
# like a number after removing '+$+', '+,+', and '+_+' as well as Rationals
|
51
|
+
# Numeric:: on object that is of class Numeric, or a string that looks like
|
52
|
+
# a number after removing '+$+', '+,+', and '+_+' as well as Rationals
|
54
53
|
# in the form /<number>:<number>/ or <number>/<number>, where <number>
|
55
54
|
# is an integer.
|
56
55
|
#
|
@@ -91,7 +90,8 @@ module FatTable
|
|
91
90
|
@raw_header.to_s.as_sym
|
92
91
|
end
|
93
92
|
@type = 'NilClass'
|
94
|
-
|
93
|
+
msg = "unknown column type '#{type}"
|
94
|
+
raise UserError, msg unless TYPES.include?(@type.to_s)
|
95
95
|
@items = []
|
96
96
|
items.each { |i| self << i }
|
97
97
|
end
|
@@ -342,7 +342,8 @@ module FatTable
|
|
342
342
|
|
343
343
|
def only_with(agg, *valid_types)
|
344
344
|
return self if valid_types.include?(type)
|
345
|
-
|
345
|
+
msg = "aggregate '#{agg}' cannot be applied to a #{type} column"
|
346
|
+
raise UserError, msg
|
346
347
|
end
|
347
348
|
|
348
349
|
public
|
@@ -366,7 +367,8 @@ module FatTable
|
|
366
367
|
# checking for type compatibility. Use the header of this Column as the
|
367
368
|
# header of the new Column.
|
368
369
|
def +(other)
|
369
|
-
|
370
|
+
msg = 'cannot combine columns with different types'
|
371
|
+
raise UserError, msg unless type == other.type
|
370
372
|
Column.new(header: header, items: items + other.items)
|
371
373
|
end
|
372
374
|
|
@@ -401,7 +403,7 @@ module FatTable
|
|
401
403
|
bool_val
|
402
404
|
end
|
403
405
|
@type =
|
404
|
-
if
|
406
|
+
if [true, false].include?(new_val)
|
405
407
|
'Boolean'
|
406
408
|
elsif new_val.is_a?(Date) || new_val.is_a?(DateTime)
|
407
409
|
'DateTime'
|
@@ -410,17 +412,19 @@ module FatTable
|
|
410
412
|
elsif new_val.is_a?(String)
|
411
413
|
'String'
|
412
414
|
else
|
413
|
-
|
415
|
+
msg = "can't add #{val} of type #{new_val.class.name} to a column"
|
416
|
+
raise UserError, msg
|
414
417
|
end
|
415
418
|
end
|
416
419
|
new_val
|
417
420
|
when 'Boolean'
|
418
|
-
if
|
421
|
+
if val.is_a?(String) && val.blank? || val.nil?
|
419
422
|
nil
|
420
423
|
else
|
421
424
|
new_val = convert_to_boolean(val)
|
422
425
|
if new_val.nil?
|
423
|
-
|
426
|
+
msg = "attempt to add '#{val}' to a column already typed as #{type}"
|
427
|
+
raise UserError, msg
|
424
428
|
end
|
425
429
|
new_val
|
426
430
|
end
|
@@ -430,7 +434,8 @@ module FatTable
|
|
430
434
|
else
|
431
435
|
new_val = convert_to_date_time(val)
|
432
436
|
if new_val.nil?
|
433
|
-
|
437
|
+
msg = "attempt to add '#{val}' to a column already typed as #{type}"
|
438
|
+
raise UserError, msg
|
434
439
|
end
|
435
440
|
new_val
|
436
441
|
end
|
@@ -440,7 +445,8 @@ module FatTable
|
|
440
445
|
else
|
441
446
|
new_val = convert_to_numeric(val)
|
442
447
|
if new_val.nil?
|
443
|
-
|
448
|
+
msg = "attempt to add '#{val}' to a column already typed as #{type}"
|
449
|
+
raise UserError, msg
|
444
450
|
end
|
445
451
|
new_val
|
446
452
|
end
|
@@ -450,7 +456,8 @@ module FatTable
|
|
450
456
|
else
|
451
457
|
new_val = convert_to_string(val)
|
452
458
|
if new_val.nil?
|
453
|
-
|
459
|
+
msg = "attempt to add '#{val}' to a column already typed as #{type}"
|
460
|
+
raise UserError, msg
|
454
461
|
end
|
455
462
|
new_val
|
456
463
|
end
|
@@ -466,15 +473,17 @@ module FatTable
|
|
466
473
|
return val if val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
467
474
|
val = val.to_s.clean
|
468
475
|
return nil if val.blank?
|
469
|
-
if val
|
476
|
+
if val.match?(/\A(false|f|n|no)\z/i)
|
470
477
|
false
|
471
|
-
elsif val
|
478
|
+
elsif val.match?(/\A(true|t|y|yes)\z/i)
|
472
479
|
true
|
473
480
|
end
|
474
481
|
end
|
475
482
|
|
476
|
-
IS0_DATE_RE = %r{\b(\d\d\d\d)[-/](\d\d?)[-/](\d\d?)\s*
|
477
|
-
|
483
|
+
IS0_DATE_RE = %r{\b(\d\d\d\d)[-/](\d\d?)[-/](\d\d?)\s*
|
484
|
+
(T\d\d:\d\d:\d\d(\+\d\d:\d\d)?)?\b}x
|
485
|
+
AMR_DATE_RE = %r{\b(\d\d?)[-/](\d\d?)[-/](\d\d\d\d)\s*
|
486
|
+
(T\d\d:\d\d:\d\d(\+\d\d:\d\d)?)?\b}x
|
478
487
|
|
479
488
|
# Convert the val to a DateTime if it is either a DateTime, a Date, or a
|
480
489
|
# String that can be parsed as a DateTime, otherwise return nil. It only
|
@@ -488,7 +497,7 @@ module FatTable
|
|
488
497
|
begin
|
489
498
|
val = val.to_s.clean
|
490
499
|
return nil if val.blank?
|
491
|
-
if val
|
500
|
+
if val.match?(IS0_DATE_RE)
|
492
501
|
val = DateTime.parse(val)
|
493
502
|
elsif val =~ AMR_DATE_RE
|
494
503
|
val = DateTime.new($3.to_i, $1.to_i, $2.to_i)
|
@@ -502,7 +511,7 @@ module FatTable
|
|
502
511
|
end
|
503
512
|
end
|
504
513
|
|
505
|
-
# Convert the val to a Numeric if is already a
|
514
|
+
# Convert the val to a Numeric if is already a Numeric or is a String that
|
506
515
|
# looks like one. Any Float is promoted to a BigDecimal. Otherwise return
|
507
516
|
# nil.
|
508
517
|
def convert_to_numeric(val)
|