Module: DataTools::IO
- Included in:
- IO
- Defined in:
- lib/data_tools/io.rb
Instance Method Summary collapse
- #configure_import(options) ⇒ Object
- #headers ⇒ Object
-
#import(opts = {}) ⇒ Object
expects a block.
- #import_options ⇒ Object
- #parseline(line) ⇒ Object
- #split(line) ⇒ Object
- #unmarshal ⇒ Object
Instance Method Details
#configure_import(options) ⇒ Object
34 35 36 |
# File 'lib/data_tools/io.rb', line 34 def configure_import() .merge!() end |
#headers ⇒ Object
8 9 10 |
# File 'lib/data_tools/io.rb', line 8 def headers @import_headers ||= @import_options[:headers] || behead end |
#import(opts = {}) ⇒ Object
expects a block
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/data_tools/io.rb', line 38 def import(opts = {}) # expects a block configure_import(opts) headers = opts[:headers] || parseline(readline) # warn "HEADERS ARE #{headers}" Enumerator.new do |yielder| self.each do |line| rec = Hash[headers.zip(parseline(line))] rec.extend DataTools::Hash yielder.yield rec.cleanse() end # need to emit anything to trigger a file-completed action? (such as pushing a batch to storage) end end |
#import_options ⇒ Object
27 28 29 30 31 32 |
# File 'lib/data_tools/io.rb', line 27 def @import_options ||= { junkwords: [], datefields: {} } end |
#parseline(line) ⇒ Object
23 24 25 |
# File 'lib/data_tools/io.rb', line 23 def parseline(line) split(line.chomp) end |
#split(line) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/data_tools/io.rb', line 12 def split(line) case [:format] when :tsv line.split("\t") when :qcq line.split('","') else # default is CSV line.parse_csv end end |
#unmarshal ⇒ Object
4 5 6 |
# File 'lib/data_tools/io.rb', line 4 def unmarshal Marshal.load(self) end |