fat_table 0.9.8 → 1.0.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/lib/fat_table.rb CHANGED
@@ -1,11 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # This module provides objects for treating tables as a data type on which you
4
- # can (1) perform operations, such as select, where, join, and others and (2)
5
- # output the tables in several formats, including text, ANSI terminal, LaTeX,
6
- # and others. It also provides several constructors for building tables from a
7
- # variety of input sources. See, e.g., .from_csv_file,
8
- # FatTable.from_org_file, and FatTable.from_sql, for more details.
3
+ # Gem Overview (extracted from README.org by gem_docs)
4
+ #
5
+ # * Introduction
6
+ # ~FatTable~ is a gem that treats tables as a data type. It provides methods for
7
+ # constructing tables from a variety of sources, building them row-by-row,
8
+ # extracting rows, columns, and cells, and performing aggregate operations on
9
+ # columns. It also provides a set of SQL-esque methods for manipulating table
10
+ # objects: ~select~ for filtering by columns or for creating new columns, ~where~
11
+ # for filtering by rows, ~order_by~ for sorting rows, ~distinct~ for eliminating
12
+ # duplicate rows, ~group_by~ for aggregating multiple rows into single rows and
13
+ # applying column aggregate methods to ungrouped columns, a collection of ~join~
14
+ # methods for combining tables, and more.
15
+ #
16
+ # Furthermore, ~FatTable~ provides methods for formatting tables and producing
17
+ # output that targets various output media: text, ANSI terminals, ruby data
18
+ # structures, LaTeX tables, Emacs org-mode tables, and more. The formatting
19
+ # methods can specify cell formatting in a way that is uniform across all the
20
+ # output methods and can also decorate the output with any number of footers,
21
+ # including group footers. ~FatTable~ applies formatting directives to the extent
22
+ # they makes sense for the output medium and treats other formatting directives as
23
+ # no-ops.
24
+ #
25
+ # ~FatTable~ can be used to perform operations on data that are naturally best
26
+ # conceived of as tables, which in my experience is quite often. It can also
27
+ # serve as a foundation for providing reporting functions where flexibility
28
+ # about the output medium can be useful. Finally ~FatTable~ can be used within
29
+ # Emacs ~org-mode~ files in code blocks targeting the Ruby language. Org mode
30
+ # tables are presented to a ruby code block as an array of arrays, so ~FatTable~
31
+ # can read them in with its ~.from_aoa~ constructor. A ~FatTable~ table output as an
32
+ # array of arrays with its ~.to_aoa~ output function will be rendered in an
33
+ # org-mode buffer as an org-table, ready for processing by other code blocks.
9
34
  module FatTable
10
35
  require 'fat_core/symbol'
11
36
  require 'fat_core/array'
@@ -18,9 +43,9 @@ module FatTable
18
43
  require 'active_support/core_ext'
19
44
  require 'active_support/number_helper'
20
45
 
46
+ require 'core_ext'
21
47
  require 'fat_table/version'
22
48
  require 'fat_table/patches'
23
- require 'ext/array'
24
49
  require 'fat_table/evaluator'
25
50
  require 'fat_table/convert'
26
51
  require 'fat_table/column'
@@ -145,11 +170,11 @@ module FatTable
145
170
  # methods can be called. If no block is given, the default format for the type
146
171
  # will be used. The +options+ are passed along to the FatTable::Formatter
147
172
  # created to process the output.
148
- def self.to_format(table, options = {}) # :yields: formatter
173
+ def self.to_format(table, **options) # :yields: formatter
149
174
  if block_given?
150
- to_any(format, table, options, &Proc.new)
175
+ to_any(format, table, **options, &Proc.new)
151
176
  else
152
- to_any(format, table, options)
177
+ to_any(format, table, **options)
153
178
  end
154
179
  end
155
180
 
@@ -159,15 +184,15 @@ module FatTable
159
184
  # +FatTable::Formatter+ of the appropriate type on which formatting and footer
160
185
  # methods can be called. If no block is given, the default format for the
161
186
  # +fmt+ type will be used.
162
- def self.to_any(fmt, table, options = {})
187
+ def self.to_any(fmt, table, **options)
163
188
  fmt = fmt.as_sym
164
189
  raise UserError, "unknown format '#{fmt}'" unless FORMATS.include?(fmt)
165
190
 
166
191
  method = "to_#{fmt}"
167
192
  if block_given?
168
- send(method, table, options, &Proc.new)
193
+ send(method, table, **options, &Proc.new)
169
194
  else
170
- send(method, table, options)
195
+ send(method, table, **options)
171
196
  end
172
197
  end
173
198
 
@@ -176,7 +201,7 @@ module FatTable
176
201
  # default formatting is applied to the +table+'s cells. If a block is given,
177
202
  # it yields the +FatTable::Formatter+ to the block on which formatting
178
203
  # and footer methods can be called.
179
- def self.to_psv(table, options = {})
204
+ def self.to_psv(table, **options)
180
205
  fmt = Formatter.new(table, options)
181
206
  yield fmt if block_given?
182
207
  fmt.output
@@ -186,8 +211,8 @@ module FatTable
186
211
  # default formatting is applies to the table's cells. If a block is given, it
187
212
  # yields an AoaFormatter to the block to which formatting instructions and
188
213
  # footers can be added by calling methods on it.
189
- def self.to_aoa(table, options = {})
190
- fmt = AoaFormatter.new(table, options)
214
+ def self.to_aoa(table, **options)
215
+ fmt = AoaFormatter.new(table, **options)
191
216
  yield fmt if block_given?
192
217
  fmt.output
193
218
  end
@@ -197,8 +222,8 @@ module FatTable
197
222
  # table. If no block is given, default formatting is applies to the table's
198
223
  # cells. If a block is given, it yields an AohFormatter to the block to which
199
224
  # formatting instructions and footers can be added by calling methods on it.
200
- def self.to_aoh(table, options = {})
201
- fmt = AohFormatter.new(table, options)
225
+ def self.to_aoh(table, **options)
226
+ fmt = AohFormatter.new(table, **options)
202
227
  yield fmt if block_given?
203
228
  fmt.output
204
229
  end
@@ -207,8 +232,8 @@ module FatTable
207
232
  # default formatting applies to the table's cells. If a block is given, it
208
233
  # yields a LaTeXFormatter to the block to which formatting instructions and
209
234
  # footers can be added by calling methods on it.
210
- def self.to_latex(table, options = {})
211
- fmt = LaTeXFormatter.new(table, options)
235
+ def self.to_latex(table, **options)
236
+ fmt = LaTeXFormatter.new(table, **options)
212
237
  yield fmt if block_given?
213
238
  fmt.output
214
239
  end
@@ -217,8 +242,8 @@ module FatTable
217
242
  # is given, default formatting applies to the table's cells. If a block is
218
243
  # given, it yields a OrgFormatter to the block to which formatting
219
244
  # instructions and footers can be added by calling methods on it.
220
- def self.to_org(table, options = {})
221
- fmt = OrgFormatter.new(table, options)
245
+ def self.to_org(table, **options)
246
+ fmt = OrgFormatter.new(table, **options)
222
247
  yield fmt if block_given?
223
248
  fmt.output
224
249
  end
@@ -227,8 +252,8 @@ module FatTable
227
252
  # table. If no block is given, default formatting applies to the table's
228
253
  # cells. If a block is given, it yields a TermFormatter to the block to which
229
254
  # formatting instructions and footers can be added by calling methods on it.
230
- def self.to_term(table, options = {})
231
- fmt = TermFormatter.new(table, options)
255
+ def self.to_term(table, **options)
256
+ fmt = TermFormatter.new(table, **options)
232
257
  yield fmt if block_given?
233
258
  fmt.output
234
259
  end
@@ -237,8 +262,8 @@ module FatTable
237
262
  # no block is given, default formatting applies to the table's cells. If a
238
263
  # block is given, it yields a TextFormatter to the block to which formatting
239
264
  # instructions and footers can be added by calling methods on it.
240
- def self.to_text(table, options = {})
241
- fmt = TextFormatter.new(table, options)
265
+ def self.to_text(table, **options)
266
+ fmt = TextFormatter.new(table, **options)
242
267
  yield fmt if block_given?
243
268
  fmt.output
244
269
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-31 00:00:00.000000000 Z
10
+ date: 2025-12-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: csv
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".envrc"
119
+ - ".github/workflows/ruby-with-dbs.yml"
119
120
  - ".gitignore"
120
121
  - ".rspec"
121
122
  - ".rubocop.yml"
@@ -123,25 +124,22 @@ files:
123
124
  - ".solargraph.yml"
124
125
  - ".travis.yml"
125
126
  - ".yardopts"
127
+ - CHANGELOG.md
128
+ - CHANGELOG.org
126
129
  - Gemfile
127
130
  - LICENSE.txt
131
+ - README.md
128
132
  - README.org
129
133
  - README.rdoc
130
134
  - Rakefile
131
135
  - TODO.org
132
136
  - bin/ft_console
133
137
  - bin/setup
134
- - examples/create_trans.sql
135
- - examples/quick.pdf
136
- - examples/quick.png
137
- - examples/quick.ppm
138
- - examples/quick.tex
139
- - examples/quick_small.png
140
- - examples/quicktable.tex
141
- - examples/trades.db
142
- - examples/trans.csv
138
+ - data/xcolors.txt
143
139
  - fat_table.gemspec
144
- - lib/ext/array.rb
140
+ - lib/core_ext.rb
141
+ - lib/core_ext/array.rb
142
+ - lib/core_ext/numeric_string.rb
145
143
  - lib/fat_table.rb
146
144
  - lib/fat_table/column.rb
147
145
  - lib/fat_table/convert.rb
@@ -157,7 +155,6 @@ files:
157
155
  - lib/fat_table/formatters/org_formatter.rb
158
156
  - lib/fat_table/formatters/term_formatter.rb
159
157
  - lib/fat_table/formatters/text_formatter.rb
160
- - lib/fat_table/formatters/xcolors.txt
161
158
  - lib/fat_table/patches.rb
162
159
  - lib/fat_table/table.rb
163
160
  - lib/fat_table/version.rb
@@ -1,14 +0,0 @@
1
- drop table trans;
2
- create table trans(date text, code text, raw, shares, price, info text, ok text);
3
- insert into trans values('2013-05-29', 'S', 15700.00, 6601.85, 24.7790, 'ENTITY3', 'F');
4
- insert into trans values('2013-05-02', 'P', 118186.40, 118186.4, 11.8500, 'ENTITY1', 'T');
5
- insert into trans values('2013-05-20', 'S', 12000.00, 5046.00, 28.2804, 'ENTITY3', 'F');
6
- insert into trans values('2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', 'T');
7
- insert into trans values('2013-05-23', 'S', 39906.00, 16780.47, 25.1749, 'ENTITY3', 'T');
8
- insert into trans values('2013-05-20', 'S', 85000.00, 35742.50, 28.3224, 'ENTITY3', 'T');
9
- insert into trans values('2013-05-02', 'P', 795546.20, 795546.2, 1.1850, 'ENTITY1', 'T');
10
- insert into trans values('2013-05-29', 'S', 13459.00, 5659.51, 24.7464, 'ENTITY3', 'T');
11
- insert into trans values('2013-05-20', 'S', 33302.00, 14003.49, 28.6383, 'ENTITY3', 'T');
12
- insert into trans values('2013-05-29', 'S', 15900.00, 6685.95, 24.5802, 'ENTITY3', 'T');
13
- insert into trans values('2013-05-30', 'S', 6679.00, 2808.52, 25.0471, 'ENTITY3', 'T');
14
- insert into trans values('2013-05-23', 'S', 23054.00, 9694.21, 26.8015, 'ENTITY3', 'F');
data/examples/quick.pdf DELETED
Binary file
data/examples/quick.png DELETED
Binary file
data/examples/quick.ppm DELETED
Binary file
data/examples/quick.tex DELETED
@@ -1,8 +0,0 @@
1
- \documentclass{article}
2
-
3
- \usepackage{longtable}
4
- \usepackage[pdftex,table,x11names]{xcolor}
5
-
6
- \begin{document}
7
- \include{quicktable.tex}
8
- \end{document}
Binary file
@@ -1,123 +0,0 @@
1
- \begin{longtable}{clcrrc}
2
- \bfseries{Ref}&
3
- \multicolumn{1}{c}{\bfseries{Date}}&
4
- \bfseries{Code}&
5
- \multicolumn{1}{c}{\bfseries{Shares}}&
6
- \multicolumn{1}{c}{\bfseries{Price}}&
7
- \bfseries{Ok}\\
8
- \endhead
9
- \bfseries{1}&
10
- 2013-05-02&
11
- P&
12
- \cellcolor{lightgray}{\textcolor{blue}{118,186.4}}&
13
- \$11.8500&
14
- Y\\
15
- \bfseries{2}&
16
- 2013-05-02&
17
- P&
18
- \cellcolor{lightgray}{\textcolor{blue}{795,546.2}}&
19
- 1.1850&
20
- Y\\
21
- \bfseries{Avg}&
22
- &
23
- \multicolumn{1}{l}{}&
24
- \bfseries{456,866.3}&
25
- \bfseries{6.5175}&
26
- \\
27
- \bfseries{3}&
28
- 2013-05-20&
29
- S&
30
- \cellcolor{lightgray}{\textcolor{blue}{5,046.0}}&
31
- 28.2804&
32
- N\\
33
- \bfseries{4}&
34
- 2013-05-20&
35
- S&
36
- \cellcolor{lightgray}{\textcolor{blue}{35,742.5}}&
37
- 28.3224&
38
- Y\\
39
- \bfseries{5}&
40
- 2013-05-20&
41
- S&
42
- \cellcolor{lightgray}{\textcolor{blue}{14,003.5}}&
43
- 28.6383&
44
- Y\\
45
- \bfseries{Avg}&
46
- &
47
- \multicolumn{1}{l}{}&
48
- \bfseries{18,264.0}&
49
- \bfseries{28.4137}&
50
- \\
51
- \bfseries{6}&
52
- 2013-05-23&
53
- S&
54
- \cellcolor{lightgray}{\textcolor{blue}{3,364.0}}&
55
- 27.1083&
56
- Y\\
57
- \bfseries{7}&
58
- 2013-05-23&
59
- S&
60
- \cellcolor{lightgray}{\textcolor{blue}{16,780.5}}&
61
- 25.1749&
62
- Y\\
63
- \bfseries{8}&
64
- 2013-05-23&
65
- S&
66
- \cellcolor{lightgray}{\textcolor{blue}{9,694.2}}&
67
- 26.8015&
68
- N\\
69
- \bfseries{Avg}&
70
- &
71
- \multicolumn{1}{l}{}&
72
- \bfseries{9,946.2}&
73
- \bfseries{26.3616}&
74
- \\
75
- \bfseries{9}&
76
- 2013-05-29&
77
- S&
78
- \cellcolor{lightgray}{\textcolor{blue}{6,601.9}}&
79
- 24.7790&
80
- N\\
81
- \bfseries{10}&
82
- 2013-05-29&
83
- S&
84
- \cellcolor{lightgray}{\textcolor{blue}{5,659.5}}&
85
- 24.7464&
86
- Y\\
87
- \bfseries{11}&
88
- 2013-05-29&
89
- S&
90
- \cellcolor{lightgray}{\textcolor{blue}{6,686.0}}&
91
- 24.5802&
92
- Y\\
93
- \bfseries{Avg}&
94
- &
95
- \multicolumn{1}{l}{}&
96
- \bfseries{6,315.8}&
97
- \bfseries{24.7019}&
98
- \\
99
- \bfseries{12}&
100
- 2013-05-30&
101
- S&
102
- \cellcolor{lightgray}{\textcolor{blue}{2,808.5}}&
103
- 25.0471&
104
- Y\\
105
- \bfseries{Avg}&
106
- &
107
- \multicolumn{1}{l}{}&
108
- \bfseries{2,808.5}&
109
- \bfseries{25.0471}&
110
- \\
111
- \bfseries{Average}&
112
- &
113
- \multicolumn{1}{l}{}&
114
- \bfseries{85,009.9}&
115
- \bfseries{23.0428}&
116
- \\
117
- \bfseries{Total}&
118
- &
119
- \multicolumn{1}{l}{}&
120
- \bfseries{1,020,119.1}&
121
- \bfseries{}&
122
- \\
123
- \end{longtable}
data/examples/trades.db DELETED
Binary file
data/examples/trans.csv DELETED
@@ -1,13 +0,0 @@
1
- 'Date', 'Code', 'Raw', 'Shares', 'Price', 'Info', 'Ok',
2
- '2013-05-29', 'S', 15700.00, 6601.85, 24.7790, 'ENTITY3', FALSE,
3
- '2013-05-02', 'P', 118186.40, 118186.4, 11.8500, 'ENTITY1', TRUE,
4
- '2013-05-20', 'S', 12000.00, 5046.00, 28.2804, 'ENTITY3', FALSE,
5
- '2013-05-23', 'S', 8000.00, 3364.00, 27.1083, 'ENTITY3', TRUE,
6
- '2013-05-23', 'S', 39906.00, 16780.47, 25.1749, 'ENTITY3', TRUE,
7
- '2013-05-20', 'S', 85000.00, 35742.50, 28.3224, 'ENTITY3', TRUE,
8
- '2013-05-02', 'P', 795546.20, 795546.2, 1.1850, 'ENTITY1', TRUE,
9
- '2013-05-29', 'S', 13459.00, 5659.51, 24.7464, 'ENTITY3', TRUE,
10
- '2013-05-20', 'S', 33302.00, 14003.49, 28.6383, 'ENTITY3', TRUE,
11
- '2013-05-29', 'S', 15900.00, 6685.95, 24.5802, 'ENTITY3', TRUE,
12
- '2013-05-30', 'S', 6679.00, 2808.52, 25.0471, 'ENTITY3', TRUE,
13
- '2013-05-23', 'S', 23054.00, 9694.21, 26.8015, 'ENTITY3', FALSE
File without changes