abstract-tables 1.0.0 → 1.0.1
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.textile +15 -5
- data/abstract-tables.gemspec +4 -2
- data/bin/atgrep +42 -0
- data/lib/abtab/driver.rb +6 -0
- data/lib/abtab/filter.rb +5 -0
- data/lib/abtab/filter/grep.rb +49 -0
- metadata +6 -4
data/README.textile
CHANGED
@@ -31,12 +31,14 @@ atcat some-file.csv some-file.tab
|
|
31
31
|
atcat csv://some-file.csv 'tab://some-file.tab?col_sep=|'
|
32
32
|
</pre>
|
33
33
|
|
34
|
-
h2.
|
34
|
+
h2. atview
|
35
35
|
|
36
36
|
<pre>
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
atview tab://some-file.tab | less
|
38
|
+
atview csv://some-file.csv | less
|
39
|
+
atview dbi://pg/localhost/database_name/table_name | less
|
40
|
+
# view a list of tables:
|
41
|
+
atview dbi://pg/localhost/database_name | less
|
40
42
|
</pre>
|
41
43
|
|
42
44
|
h2. atcat
|
@@ -44,7 +46,15 @@ h2. atcat
|
|
44
46
|
Limitations: only implemented 'driver' is dbi. Only supported output port is stdout as tab delimited.
|
45
47
|
|
46
48
|
<pre>
|
47
|
-
atcat dbi://user:pass@Pg/localhost/db_name/table_name |
|
49
|
+
atcat dbi://user:pass@Pg/localhost/db_name/table_name | atview | less
|
50
|
+
</pre>
|
51
|
+
|
52
|
+
h2. atgrep
|
53
|
+
|
54
|
+
Filter a table source by passing an expression, which has access to the record via the var @r@:
|
55
|
+
|
56
|
+
<pre>
|
57
|
+
atgrep -e 'r[0] == "this"' test/fixtures/files/file1.csv | atview
|
48
58
|
</pre>
|
49
59
|
|
50
60
|
h1. Suported Drivers
|
data/abstract-tables.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
SPEC = Gem::Specification.new do |s|
|
4
4
|
s.name = "abstract-tables"
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.1"
|
6
6
|
s.date = '2011-02-09'
|
7
7
|
s.authors = ["Kyle Burton"]
|
8
8
|
s.email = "kyle.burton@gmail.com"
|
@@ -22,15 +22,17 @@ DESC
|
|
22
22
|
s.summary = "Table Abstraction as a URI : Record Streams, Filters, ETL Ginsu"
|
23
23
|
s.homepage = "http://github.com/kyleburton/abstract-tables"
|
24
24
|
s.files = %w[
|
25
|
-
abstract-tables-1.0.0.gem
|
26
25
|
abstract-tables.gemspec
|
27
26
|
bin/atcat
|
28
27
|
bin/atview
|
28
|
+
bin/atgrep
|
29
29
|
introducing-abtab/README.textile
|
30
30
|
lib/abtab/driver.rb
|
31
31
|
lib/abtab/drivers/csv_driver.rb
|
32
32
|
lib/abtab/drivers/dbi_driver.rb
|
33
33
|
lib/abtab/drivers/tab_driver.rb
|
34
|
+
lib/abtab/filter/grep.rb
|
35
|
+
lib/abtab/filter.rb
|
34
36
|
lib/abtab.rb
|
35
37
|
README.textile
|
36
38
|
test/fixtures/files/file1.csv
|
data/bin/atgrep
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'abtab'
|
4
|
+
require 'abtab/filter/grep'
|
5
|
+
require 'base_app'
|
6
|
+
|
7
|
+
class GrepApp < BaseApp
|
8
|
+
def command_line_arguments
|
9
|
+
super.concat [
|
10
|
+
['e','expression','Grep Expression',true]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
input_uri = nil
|
16
|
+
if File.pipe?('/dev/stdin')
|
17
|
+
input_uri = 'tab:///dev/stdin'
|
18
|
+
else
|
19
|
+
input_uri = ARGV.shift or raise "You must speicfy a URI to grep"
|
20
|
+
end
|
21
|
+
|
22
|
+
flt = Abtab::Filter::Grep.new input_uri
|
23
|
+
flt.open_for_reading
|
24
|
+
# TODO: getopt args for
|
25
|
+
proc = eval("Proc.new {|r| #{self.expression} }")
|
26
|
+
flt.filter_predicate = proc
|
27
|
+
#puts "flt=#{flt}"
|
28
|
+
|
29
|
+
outp = nil
|
30
|
+
if ARGV.empty?
|
31
|
+
outp = Abtab.write_handle 'tab:///dev/stdout'
|
32
|
+
else
|
33
|
+
outp = Abtab.write_handle ARGV.shift
|
34
|
+
end
|
35
|
+
|
36
|
+
outp.import flt
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if $0 == __FILE__
|
41
|
+
GrepApp.main
|
42
|
+
end
|
data/lib/abtab/driver.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Abtab
|
2
2
|
class Driver
|
3
|
+
|
4
|
+
[:open_for_reading, :open_for_writing, :next_record, :write_record].each do |m|
|
5
|
+
define_method(m) { raise "Error: #{m} not implemented in: #{self.class}" }
|
6
|
+
end
|
7
|
+
|
3
8
|
def import inp
|
9
|
+
set_columns inp.columns
|
4
10
|
while rec = inp.next_record
|
5
11
|
break if rec.nil?
|
6
12
|
write_record rec
|
data/lib/abtab/filter.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'abtab/filter'
|
2
|
+
|
3
|
+
module Abtab
|
4
|
+
class Filter::Grep < Abtab::Filter
|
5
|
+
def initialize url
|
6
|
+
@url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter_predicate= p
|
10
|
+
@filter = p
|
11
|
+
end
|
12
|
+
|
13
|
+
def open_for_reading url=@url
|
14
|
+
@url = url
|
15
|
+
@driver = Abtab.read_handle @url
|
16
|
+
end
|
17
|
+
|
18
|
+
def next_record
|
19
|
+
rec = nil
|
20
|
+
while rec = @driver.next_record
|
21
|
+
if @filter.call(rec)
|
22
|
+
break
|
23
|
+
else
|
24
|
+
#puts "rejecting: #{rec.inspect}"
|
25
|
+
0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return rec
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_columns cols
|
32
|
+
@driver.set_columns cols
|
33
|
+
end
|
34
|
+
|
35
|
+
def columns
|
36
|
+
@driver.columns
|
37
|
+
end
|
38
|
+
|
39
|
+
def open_for_writing url=@url
|
40
|
+
raise "Error: grep does not support writing."
|
41
|
+
@driver = Abtab.write_handle @url
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_record
|
45
|
+
raise "Error: grep does not support writing."
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstract-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kyle Burton
|
@@ -54,15 +54,17 @@ extensions: []
|
|
54
54
|
extra_rdoc_files:
|
55
55
|
- README.textile
|
56
56
|
files:
|
57
|
-
- abstract-tables-1.0.0.gem
|
58
57
|
- abstract-tables.gemspec
|
59
58
|
- bin/atcat
|
60
59
|
- bin/atview
|
60
|
+
- bin/atgrep
|
61
61
|
- introducing-abtab/README.textile
|
62
62
|
- lib/abtab/driver.rb
|
63
63
|
- lib/abtab/drivers/csv_driver.rb
|
64
64
|
- lib/abtab/drivers/dbi_driver.rb
|
65
65
|
- lib/abtab/drivers/tab_driver.rb
|
66
|
+
- lib/abtab/filter/grep.rb
|
67
|
+
- lib/abtab/filter.rb
|
66
68
|
- lib/abtab.rb
|
67
69
|
- README.textile
|
68
70
|
- test/fixtures/files/file1.csv
|