Sha256: 6def8d5d0c9e782e89f6703d12176876f9a19e8010cdf0d19e0e7a3efad014c3
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require 'csv' require 'open-uri' module I2X ## # = CSVDetector # # Detect changes in CSV files (using column numbers). # class CSVDetector < Detector public ## # == Detect the changes # def detect object p "[i2x][CSV] Testing #{object[:uri]}" CSV.new(open(object[:uri]), :headers => :first_row).each do |row| begin unless object[:cache].nil? then p "[i2x][CSV] with cache, verifying" @response = Cashier.verify row[object[:cache].to_i], object, row, object[:seed] else p "[i2x][CSV] no cache, verifying" @cache = Cashier.verify row[0], object, row, object[:seed] end rescue Exception => e p "[i2x][CSVDetector] loading error: #{e.inspect}" end begin @cache = JSON.parse(@response, {:symbolize_names => true}) @cache[:templates].each do |t| @templates.push t end # The actual processing # if @cache[:cache][:status] == 100 then # add row data to payload from selectors (key => key, value => column name) payload = Hash.new object[:selectors].each do |selector| selector.each do |k,v| payload[k] = row[v.to_i] end end # add payload object to payloads list @payloads.push payload end rescue Exception => e p "[i2x][CSVDetector] processing error: #{e.inspect}" end @cache[:templates] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
i2x-0.0.6 | lib/i2x/csvdetector.rb |