fat_table 0.2.7 → 0.2.8
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 +5 -5
- data/.travis.yml +1 -0
- data/.yardopts +5 -1
- data/README.org +34 -30
- data/fat_table.gemspec +1 -0
- data/lib/fat_table/db_handle.rb +1 -41
- data/lib/fat_table/table.rb +1 -1
- data/lib/fat_table/version.rb +1 -1
- data/{README.md → md/README.md} +1 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 558944c93313d81954da19744fec105b8562a4634781f77accd0fd7677dce76b
|
4
|
+
data.tar.gz: e301c37c690d01a77a24679e676c35cefd0f68b01d72b4e16835e54e44223790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6430e39eb4261ab51eb855a0e3119e7bfae2e0f104215e637d8091d8d2ba4847f8b2e91ee1b1be08531bc69a72dc4a4b6233fbbc2d0f8fa7b43c11c73ac8c305
|
7
|
+
data.tar.gz: 1eec9ab1576cdda1ebdcd0833601573f343ecab9cd16244c6fd4038b6a3dc86ba7303b693e7c7d852ef1443e9b2b3d20b9ff32ccb652fcb73a92e7337d3511c7
|
data/.travis.yml
CHANGED
data/.yardopts
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
|
[](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
|
@@ -76,7 +80,7 @@ Or install it yourself as:
|
|
76
80
|
|
77
81
|
~FatTable~ provides table objects as a data type that can be constructed and
|
78
82
|
operated on in a number of ways. Here's a quick example to illustrate the use of
|
79
|
-
|
83
|
+
~FatTable~. See the detailed explanations further on down.
|
80
84
|
|
81
85
|
#+HEADER: :colnames no :session readme :hlines yes :wrap EXAMPLE :exports both
|
82
86
|
#+BEGIN_SRC ruby
|
@@ -165,11 +169,12 @@ the main features of ~FatTable~. See the detailed explanations further on down.
|
|
165
169
|
|
166
170
|
** A Word About the Examples
|
167
171
|
|
168
|
-
When you install the ~fat_table~ gem, you have access to a program ~ft_console
|
172
|
+
When you install the ~fat_table~ gem, you have access to a program ~ft_console~,
|
169
173
|
which opens a ~pry~ session with ~fat_table~ loaded and the tables used in the
|
170
174
|
examples in this ~README~ defined as instance variables so you can experiment
|
171
175
|
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
|
176
|
+
~tab1~ as ~@tab1~ in ~ft_console~, but otherwise the examples should work as
|
177
|
+
shown in this ~README~.
|
173
178
|
|
174
179
|
The examples in this ~README~ file are executed as code blocks within the
|
175
180
|
~README.org~ file, so they typically end with a call to ~.to_aoa~. That causes
|
@@ -231,7 +236,7 @@ locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_ lib str version
|
|
231
236
|
[4] pry(main)>
|
232
237
|
#+END_EXAMPLE
|
233
238
|
|
234
|
-
|
239
|
+
If you use ~puts table.to_term~, you can see the effect of the color formatting
|
235
240
|
directives.
|
236
241
|
|
237
242
|
** Anatomy of a Table
|
@@ -478,15 +483,15 @@ This example illustrates several things:
|
|
478
483
|
where the number of shares is greater than 500. More on that later.
|
479
484
|
4. ~FatTable~ passes back to org-mode an array of arrays using the ~.to_aoa~
|
480
485
|
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
|
486
|
+
apply ~.to_aoa~ at the end of example blocks in this ~README~ to render the
|
487
|
+
results as a table inside this file. As we'll see below, ~.to_aoa~ can also
|
488
|
+
take a block to which formatting and footer directives can be attached.
|
484
489
|
|
485
490
|
*** From Arrays of Hashes
|
486
491
|
|
487
492
|
A second ruby data structure that can be used to initialize a ~FatTable~ table
|
488
493
|
is an array of ruby Hashes. Each hash represents a row of the table, and the
|
489
|
-
headers of the table are
|
494
|
+
headers of the table are taken from the keys of the hashes. Accordingly, all the
|
490
495
|
hashes should have the same keys.
|
491
496
|
|
492
497
|
This same method can in fact take an array of any objects that can be converted
|
@@ -517,7 +522,7 @@ tab = FatTable.from_aoh(aoh)
|
|
517
522
|
#+END_SRC
|
518
523
|
|
519
524
|
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.
|
525
|
+
or strings that can be parsed into one of the permissible column types.
|
521
526
|
|
522
527
|
*** From SQL queries
|
523
528
|
|
@@ -528,29 +533,19 @@ database parameters to be used for the queries.
|
|
528
533
|
#+BEGIN_SRC ruby
|
529
534
|
# This automatically requires sequel.
|
530
535
|
require 'fat_table'
|
531
|
-
FatTable.set_db(
|
536
|
+
FatTable.set_db(adapter: 'postgres',
|
532
537
|
database: 'XXX_development',
|
533
|
-
user: '
|
534
|
-
password: '
|
535
|
-
host: '
|
536
|
-
socket: '/tmp/.s.PGSQL.5432')
|
538
|
+
user: 'ken',
|
539
|
+
password: 'imsecret',
|
540
|
+
host: 'db.lan')
|
537
541
|
tab = FatTable.from_sql('select * from trades;')
|
538
542
|
#+END_SRC
|
539
543
|
|
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:
|
544
|
+
The arguments to ~set_db~ are simply passed on to ~sequel~'s connect method, so
|
545
|
+
any set of arguments that work for it should work for ~set_db~. Alternatively,
|
546
|
+
you can build the ~Sequel~ connection directly with ~Sequel.connect~ or with
|
547
|
+
adapter-specific ~Sequel~ connection methods and let ~FatTable~ know to use that
|
548
|
+
connection:
|
554
549
|
|
555
550
|
#+BEGIN_SRC ruby
|
556
551
|
require 'fat_table'
|
@@ -561,8 +556,15 @@ that connection:
|
|
561
556
|
Consult ~Sequel's~ documentation for details on its connection methods.
|
562
557
|
[[http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html]]
|
563
558
|
|
559
|
+
The ~.set_db~ function need only be called once, and the database handle it
|
560
|
+
creates will be used for all subsequent ~.from_sql~ calls until ~.set_db~ is
|
561
|
+
called again.
|
562
|
+
|
564
563
|
*** Marking Groups in Input
|
565
564
|
|
565
|
+
~FatTable~ tables has a concept of "groups" of rows that play a role in many of
|
566
|
+
the methods for operating on them as explained [[Groups][below]].
|
567
|
+
|
566
568
|
The ~.from_aoa~ and ~.from_aoh~ functions take an optional keyword parameter
|
567
569
|
~hlines:~ that, if set to ~true~, causes them to mark group boundaries in the
|
568
570
|
table wherever a row Array (for ~.from_aoa~) or Hash (for ~.from_aoh~) is
|
@@ -582,6 +584,7 @@ beginning with something like '~|---~'. The ~.from_org_...~ functions always
|
|
582
584
|
recognizes hlines in the input, so it takes no ~hlines:~ keyword parameter.
|
583
585
|
|
584
586
|
** Accessing Parts of Tables
|
587
|
+
|
585
588
|
*** Rows
|
586
589
|
|
587
590
|
A ~FatTable~ table is an Enumerable, yielding each row of the table as a Hash
|
@@ -637,6 +640,7 @@ operation, which mutates the receiver table by removing its group boundaries.
|
|
637
640
|
Second, because each operation returns a ~FatTable::Table~ object, the
|
638
641
|
operations are chainable.
|
639
642
|
|
643
|
+
<<Groups>>
|
640
644
|
Third, ~FatTable::Table~ objects can have "groups" of rows within the table.
|
641
645
|
These can be decorated with hlines and group footers on output. Some of these
|
642
646
|
operations result in marking group boundaries in the result table, others remove
|
data/fat_table.gemspec
CHANGED
@@ -72,6 +72,7 @@ Gem::Specification.new do |spec|
|
|
72
72
|
spec.add_development_dependency 'rake', '~> 10.0'
|
73
73
|
spec.add_development_dependency 'redcarpet'
|
74
74
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
75
|
+
spec.add_development_dependency 'rubocop-rspec'
|
75
76
|
spec.add_development_dependency 'simplecov'
|
76
77
|
|
77
78
|
spec.add_runtime_dependency 'activesupport', '>3.0'
|
data/lib/fat_table/db_handle.rb
CHANGED
@@ -18,7 +18,7 @@ module FatTable
|
|
18
18
|
# Sequel's adapter-specific connection methods.
|
19
19
|
# http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html
|
20
20
|
#
|
21
|
-
# +
|
21
|
+
# +adapter+::
|
22
22
|
# One of 'pg' (for Postgresql), 'mysql' or 'mysql2' (for Mysql), or
|
23
23
|
# 'sqlite' (for SQLite3) to specify the +Sequel+ driver to use. You may
|
24
24
|
# have to install the driver to make this work. By default use 'Pg'.
|
@@ -61,46 +61,6 @@ module FatTable
|
|
61
61
|
handle
|
62
62
|
end
|
63
63
|
|
64
|
-
# def self.set_db(adapter: 'postgres',
|
65
|
-
# database:,
|
66
|
-
# user: ENV['LOGNAME'],
|
67
|
-
# password: nil,
|
68
|
-
# host: 'localhost',
|
69
|
-
# port: nil,
|
70
|
-
# socket: '/tmp/.s.PGSQL.5432')
|
71
|
-
# if db
|
72
|
-
# self.handle = db
|
73
|
-
# else
|
74
|
-
# raise UserError, 'must supply database name to set_db' unless database
|
75
|
-
|
76
|
-
# valid_drivers = %w[postgres mysql mysql2 sqlite]
|
77
|
-
# unless valid_drivers.include?(driver)
|
78
|
-
# msg = "'#{driver}' driver must be one of #{valid_drivers.join(' or ')}"
|
79
|
-
# raise UserError, msg
|
80
|
-
# end
|
81
|
-
# if database.blank?
|
82
|
-
# raise UserError, 'must supply database parameter to set_db'
|
83
|
-
# end
|
84
|
-
|
85
|
-
# if driver == 'sqlite'
|
86
|
-
# dsn = "sqlite://#{database}"
|
87
|
-
# else
|
88
|
-
# pw_part = password ? ":#{password}" : ''
|
89
|
-
# hst_part = host ? "@#{host}" : ''
|
90
|
-
# prt_part = port ? ":#{port}" : ''
|
91
|
-
# dsn = "#{driver}:://#{user}#{pw_part}#{hst_part}#{prt_part}/#{database}"
|
92
|
-
# end
|
93
|
-
|
94
|
-
# # Set the dsn for Sequel
|
95
|
-
# begin
|
96
|
-
# self.handle = Sequel.connect(dsn)
|
97
|
-
# rescue Sequel::Error => ex
|
98
|
-
# raise TransientError, "#{dsn}: #{ex}"
|
99
|
-
# end
|
100
|
-
# end
|
101
|
-
# handle
|
102
|
-
# end
|
103
|
-
|
104
64
|
# Return the +Sequel+ database handle.
|
105
65
|
def self.db
|
106
66
|
handle
|
data/lib/fat_table/table.rb
CHANGED
data/lib/fat_table/version.rb
CHANGED
data/{README.md → md/README.md}
RENAMED
@@ -44,8 +44,7 @@
|
|
44
44
|
4. [Development](#org62e325b)
|
45
45
|
5. [Contributing](#orgf51a2c9)
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
[](https://travis-ci.org/ddoherty03/fat_table)
|
49
48
|
|
50
49
|
<a id="org23d768e"></a>
|
51
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: simplecov
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -280,7 +294,6 @@ files:
|
|
280
294
|
- ".yardopts"
|
281
295
|
- Gemfile
|
282
296
|
- LICENSE.txt
|
283
|
-
- README.md
|
284
297
|
- README.org
|
285
298
|
- README.rdoc
|
286
299
|
- Rakefile
|
@@ -304,6 +317,7 @@ files:
|
|
304
317
|
- lib/fat_table/patches.rb
|
305
318
|
- lib/fat_table/table.rb
|
306
319
|
- lib/fat_table/version.rb
|
320
|
+
- md/README.md
|
307
321
|
homepage: https://github.com/ddoherty03/fat_table
|
308
322
|
licenses: []
|
309
323
|
metadata:
|
@@ -325,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
339
|
version: '0'
|
326
340
|
requirements: []
|
327
341
|
rubyforge_project:
|
328
|
-
rubygems_version: 2.
|
342
|
+
rubygems_version: 2.7.3
|
329
343
|
signing_key:
|
330
344
|
specification_version: 4
|
331
345
|
summary: Provides tools for working with tables as a data type.
|