abstract-tables 1.0.2 → 1.0.3
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/abstract-tables.gemspec +4 -2
 - data/bin/atcat +2 -2
 - data/bin/atview +1 -1
 - data/lib/abtab/drivers/xls_driver.rb +79 -0
 - metadata +22 -4
 
    
        data/abstract-tables.gemspec
    CHANGED
    
    | 
         @@ -2,8 +2,8 @@ require 'rubygems' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            SPEC = Gem::Specification.new do |s|
         
     | 
| 
       4 
4 
     | 
    
         
             
              s.name = "abstract-tables"
         
     | 
| 
       5 
     | 
    
         
            -
              s.version = "1.0. 
     | 
| 
       6 
     | 
    
         
            -
              s.date = '2011-02- 
     | 
| 
      
 5 
     | 
    
         
            +
              s.version = "1.0.3"
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.date = '2011-02-15'
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.authors = ["Kyle Burton"]
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.email = "kyle.burton@gmail.com"
         
     | 
| 
       9 
9 
     | 
    
         
             
              s.platform = Gem::Platform::RUBY
         
     | 
| 
         @@ -31,6 +31,7 @@ DESC 
     | 
|
| 
       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/drivers/xls_driver.rb
         
     | 
| 
       34 
35 
     | 
    
         
             
                lib/abtab/filter/grep.rb
         
     | 
| 
       35 
36 
     | 
    
         
             
                lib/abtab/filter.rb
         
     | 
| 
       36 
37 
     | 
    
         
             
                lib/abtab.rb
         
     | 
| 
         @@ -43,5 +44,6 @@ DESC 
     | 
|
| 
       43 
44 
     | 
    
         
             
              s.require_paths = %w[lib bin]
         
     | 
| 
       44 
45 
     | 
    
         
             
              s.extra_rdoc_files = %w[README.textile] #  LICENSE]
         
     | 
| 
       45 
46 
     | 
    
         
             
              s.add_runtime_dependency('dbi', [">= 0.4.5"])
         
     | 
| 
      
 47 
     | 
    
         
            +
              s.add_runtime_dependency('spreadsheet', [">= 0.6.5.2"])
         
     | 
| 
       46 
48 
     | 
    
         
             
              s.has_rdoc = false
         
     | 
| 
       47 
49 
     | 
    
         
             
            end
         
     | 
    
        data/bin/atcat
    CHANGED
    
    
    
        data/bin/atview
    CHANGED
    
    
| 
         @@ -0,0 +1,79 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spreadsheet'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Abtab::Driver::XlsDriver < Abtab::Driver
         
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize url
         
     | 
| 
      
 5 
     | 
    
         
            +
                @read_index = 1
         
     | 
| 
      
 6 
     | 
    
         
            +
                @read_worksheet_index = 0
         
     | 
| 
      
 7 
     | 
    
         
            +
                @write_index = 0
         
     | 
| 
      
 8 
     | 
    
         
            +
                @options = {}
         
     | 
| 
      
 9 
     | 
    
         
            +
                @options["client_encoding"] = "UTF-8"
         
     | 
| 
      
 10 
     | 
    
         
            +
                @schema, @file, @options = url_parse url, @options
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def open_for_reading
         
     | 
| 
      
 14 
     | 
    
         
            +
                if !File.exists? @file
         
     | 
| 
      
 15 
     | 
    
         
            +
                  raise "Error: can not open for reading, file does not exist: #{@file}"
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                book = Spreadsheet.open @file
         
     | 
| 
      
 19 
     | 
    
         
            +
                if @options["worksheet"]
         
     | 
| 
      
 20 
     | 
    
         
            +
                  unless book.worksheets.detect { |ws| ws.name == @options["worksheet"] }
         
     | 
| 
      
 21 
     | 
    
         
            +
                    raise "Error: specified worksheet (#{@options['worksheet']}) not found in workbook."
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @read_fh = book.worksheet @options["worksheet"]
         
     | 
| 
      
 24 
     | 
    
         
            +
                else
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @read_fh = book.worksheet 0
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                header_line = @read_fh.row 0
         
     | 
| 
      
 29 
     | 
    
         
            +
                @columns = parse_line header_line
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def parse_line l
         
     | 
| 
      
 33 
     | 
    
         
            +
                # For now, coerce everything string
         
     | 
| 
      
 34 
     | 
    
         
            +
                l.collect { |v| v.to_s }
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              def columns
         
     | 
| 
      
 38 
     | 
    
         
            +
                @columns
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              def next_record
         
     | 
| 
      
 42 
     | 
    
         
            +
                if @read_index >= @read_fh.count
         
     | 
| 
      
 43 
     | 
    
         
            +
                  line = nil
         
     | 
| 
      
 44 
     | 
    
         
            +
                else
         
     | 
| 
      
 45 
     | 
    
         
            +
                  line = parse_line @read_fh.row @read_index
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @read_index += 1
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
                line
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def close
         
     | 
| 
      
 52 
     | 
    
         
            +
                if @read_fh
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @read_fh = nil
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
                if @write_fh
         
     | 
| 
      
 56 
     | 
    
         
            +
                  @write_fh.write @file
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @write_fh = nil
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              def open_for_writing
         
     | 
| 
      
 62 
     | 
    
         
            +
                @write_fh = Spreadsheet::Workbook.new
         
     | 
| 
      
 63 
     | 
    
         
            +
                @write_sheet = @write_fh.create_worksheet
         
     | 
| 
      
 64 
     | 
    
         
            +
                set_columns(@columns) if @columns && !@columns.empty
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              def write_record rec
         
     | 
| 
      
 68 
     | 
    
         
            +
                @write_sheet.row(@write_index).replace rec
         
     | 
| 
      
 69 
     | 
    
         
            +
                @write_index += 1
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
              def set_columns cols
         
     | 
| 
      
 73 
     | 
    
         
            +
                @columns = cols
         
     | 
| 
      
 74 
     | 
    
         
            +
                write_record @columns
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            Abtab.register 'xls', Abtab::Driver::XlsDriver
         
     | 
    
        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: 17
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 3
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Kyle Burton
         
     | 
| 
         @@ -15,7 +15,7 @@ autorequire: 
     | 
|
| 
       15 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
16 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2011-02- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2011-02-15 00:00:00 -05:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -34,6 +34,23 @@ dependencies: 
     | 
|
| 
       34 
34 
     | 
    
         
             
                    version: 0.4.5
         
     | 
| 
       35 
35 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: *id001
         
     | 
| 
      
 37 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 38 
     | 
    
         
            +
              name: spreadsheet
         
     | 
| 
      
 39 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 40 
     | 
    
         
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 41 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 42 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 43 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 44 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 45 
     | 
    
         
            +
                    hash: 111
         
     | 
| 
      
 46 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 47 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 48 
     | 
    
         
            +
                    - 6
         
     | 
| 
      
 49 
     | 
    
         
            +
                    - 5
         
     | 
| 
      
 50 
     | 
    
         
            +
                    - 2
         
     | 
| 
      
 51 
     | 
    
         
            +
                    version: 0.6.5.2
         
     | 
| 
      
 52 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 53 
     | 
    
         
            +
              version_requirements: *id002
         
     | 
| 
       37 
54 
     | 
    
         
             
            description: |+
         
     | 
| 
       38 
55 
     | 
    
         
             
              The best I could come up with was to just show you: 
         
     | 
| 
       39 
56 
     | 
    
         | 
| 
         @@ -63,6 +80,7 @@ files: 
     | 
|
| 
       63 
80 
     | 
    
         
             
            - lib/abtab/drivers/csv_driver.rb
         
     | 
| 
       64 
81 
     | 
    
         
             
            - lib/abtab/drivers/dbi_driver.rb
         
     | 
| 
       65 
82 
     | 
    
         
             
            - lib/abtab/drivers/tab_driver.rb
         
     | 
| 
      
 83 
     | 
    
         
            +
            - lib/abtab/drivers/xls_driver.rb
         
     | 
| 
       66 
84 
     | 
    
         
             
            - lib/abtab/filter/grep.rb
         
     | 
| 
       67 
85 
     | 
    
         
             
            - lib/abtab/filter.rb
         
     | 
| 
       68 
86 
     | 
    
         
             
            - lib/abtab.rb
         
     |