abstract-tables 1.0.1 → 1.0.2

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.
@@ -9,6 +9,8 @@ h2. atcat
9
9
 
10
10
  <pre>
11
11
  # dump a postgres table to the console (default is tab delimited)
12
+ atcat dbi://user:pass@Pg/localhost/db_name/table_name | atview | less
13
+ # if you create an $HOME/.abtab.dbrc (see below), you can omit the user/pass:
12
14
  atcat dbi://pg/localhost/database_name/table_name
13
15
 
14
16
  # export a table to a tab file:
@@ -41,12 +43,6 @@ atview dbi://pg/localhost/database_name/table_name | less
41
43
  atview dbi://pg/localhost/database_name | less
42
44
  </pre>
43
45
 
44
- h2. atcat
45
-
46
- Limitations: only implemented 'driver' is dbi. Only supported output port is stdout as tab delimited.
47
-
48
- <pre>
49
- atcat dbi://user:pass@Pg/localhost/db_name/table_name | atview | less
50
46
  </pre>
51
47
 
52
48
  h2. atgrep
@@ -55,8 +51,22 @@ Filter a table source by passing an expression, which has access to the record v
55
51
 
56
52
  <pre>
57
53
  atgrep -e 'r[0] == "this"' test/fixtures/files/file1.csv | atview
54
+
55
+ # ruby is mutable, so if you feel like being naughty, you can modify during the grep:
56
+ atgrep -e 'r[0] = r[0].upcase; r[0] == "THIS"' test/fixtures/files/file1.csv
57
+
58
+ # but that's what atmod is for...
58
59
  </pre>
59
60
 
61
+ h2. atcut
62
+
63
+ Filter a source, selecting specific columns.
64
+
65
+ <pre>
66
+ # pull only the first and 3rd column:
67
+ bin/atcut -f 1,3 test/fixtures/files/file1.tab
68
+ <pre>
69
+
60
70
  h1. Suported Drivers
61
71
 
62
72
  h2. tab
@@ -79,6 +89,30 @@ h3. quote_char
79
89
 
80
90
  Override the default quote_char (").
81
91
 
92
+ h2. dbi
93
+
94
+ (only tested with PostgreSQL)
95
+
96
+ h3. @$HOME/.abtab.dbrc@
97
+
98
+ With the dbi driver, you can create the file @.abtab.dbrc@ in your home directory and include the connection credentails for the databases you commonly use. It must be a YAML file, you can create it from a ruby script or irb with:
99
+
100
+ <pre>
101
+ require 'yaml'
102
+
103
+ cfg = {
104
+ "localhost" => {
105
+ "database_name" => {
106
+ "user" => "username",
107
+ "pass" => "password"
108
+ }
109
+ }
110
+ }
111
+ File.open("#{ENV['HOME']}/.abtab.dbrc","w") do |f|
112
+ f.puts cfg.to_yaml
113
+ end
114
+ </pre>
115
+
82
116
  h1. License
83
117
 
84
118
  h1. Authors
@@ -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.1"
5
+ s.version = "1.0.2"
6
6
  s.date = '2011-02-09'
7
7
  s.authors = ["Kyle Burton"]
8
8
  s.email = "kyle.burton@gmail.com"
data/bin/atgrep CHANGED
@@ -7,7 +7,8 @@ require 'base_app'
7
7
  class GrepApp < BaseApp
8
8
  def command_line_arguments
9
9
  super.concat [
10
- ['e','expression','Grep Expression',true]
10
+ ['e','expression=s','Grep Expression',true],
11
+ ['v','invert','Invert the predicate']
11
12
  ]
12
13
  end
13
14
 
@@ -19,12 +20,10 @@ class GrepApp < BaseApp
19
20
  input_uri = ARGV.shift or raise "You must speicfy a URI to grep"
20
21
  end
21
22
 
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}"
23
+ flt = Abtab::Filter::Grep.new Abtab.read_handle input_uri
24
+ inv = self.invert ? "!" : ""
25
+ pred = eval("Proc.new {|r| #{inv}(#{self.expression}) }")
26
+ flt.filter_predicate = pred
28
27
 
29
28
  outp = nil
30
29
  if ARGV.empty?
@@ -1,5 +1,9 @@
1
1
  require 'abtab/driver'
2
2
  module Abtab
3
3
  class Filter
4
+ attr_accessor :driver
5
+ def initialize driver
6
+ @driver = driver
7
+ end
4
8
  end
5
9
  end
@@ -2,48 +2,26 @@ require 'abtab/filter'
2
2
 
3
3
  module Abtab
4
4
  class Filter::Grep < Abtab::Filter
5
- def initialize url
6
- @url = url
7
- end
8
5
 
9
6
  def filter_predicate= p
10
7
  @filter = p
11
8
  end
12
9
 
13
- def open_for_reading url=@url
14
- @url = url
15
- @driver = Abtab.read_handle @url
16
- end
17
-
18
10
  def next_record
19
11
  rec = nil
20
- while rec = @driver.next_record
12
+ while rec = driver.next_record
21
13
  if @filter.call(rec)
22
14
  break
23
15
  else
24
- #puts "rejecting: #{rec.inspect}"
25
16
  0
26
17
  end
27
18
  end
28
19
  return rec
29
20
  end
30
21
 
31
- def set_columns cols
32
- @driver.set_columns cols
33
- end
34
-
35
22
  def columns
36
23
  @driver.columns
37
24
  end
38
25
 
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
26
  end
49
27
  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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kyle Burton