Module: Abtab
- Defined in:
- lib/abtab.rb,
lib/abtab/driver.rb,
lib/abtab/filter.rb,
lib/abtab/filter/grep.rb
Defined Under Namespace
Constant Summary collapse
- REGISTERED_DRIVERS =
{}
Class Method Summary collapse
- .open(thing) ⇒ Object
- .open_file(thing) ⇒ Object
- .read_handle(uri) ⇒ Object
- .register(schema, driver) ⇒ Object
- .write_handle(uri) ⇒ Object
Class Method Details
.open(thing) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/abtab.rb', line 10 def self.open thing if thing !~ /^.+?:\/\// return self.open_file thing end viable_drivers = REGISTERED_DRIVERS.keys.select do |schema| thing.start_with? schema end if 0 == viable_drivers.size raise "Error: there is no registered driver for url: #{thing}" end if 1 == viable_drivers.size REGISTERED_DRIVERS[viable_drivers.first].new thing end end |
.open_file(thing) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/abtab.rb', line 40 def self.open_file thing # TODO: put in some more 'magick' -- use some hueristics to figure out the likely format by looking at the first few lines... if thing =~ /.tab$/ return self.open "tab://#{thing}" end if thing =~ /.csv$/ return self.open "csv://#{thing}" end if thing =~ /.xls$/ return self.open "xls://#{thing}" end # tab delimited is the default return self.open "tab://#{thing}" end |
.read_handle(uri) ⇒ Object
28 29 30 31 32 |
# File 'lib/abtab.rb', line 28 def self.read_handle uri driver = self.open uri driver.open_for_reading driver end |
.register(schema, driver) ⇒ Object
6 7 8 |
# File 'lib/abtab.rb', line 6 def self.register schema, driver REGISTERED_DRIVERS[schema] = driver end |
.write_handle(uri) ⇒ Object
34 35 36 37 38 |
# File 'lib/abtab.rb', line 34 def self.write_handle uri driver = self.open uri driver.open_for_writing driver end |