Class: I2X::CSVDetector

Inherits:
Detector show all
Defined in:
lib/i2x/csvdetector.rb

Overview

CSVDetector

Detect changes in CSV files (using column numbers).

Instance Attribute Summary

Attributes inherited from Detector

#agent, #content, #identifier, #objects, #payloads

Instance Method Summary collapse

Methods inherited from Detector

#checkup, #initialize

Constructor Details

This class inherits a constructor from I2X::Detector

Instance Method Details

#detect(object) ⇒ Object

Detect the changes



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/i2x/csvdetector.rb', line 23

def detect object
  begin
    CSV.new(open(object[:uri]), :headers => :first_row).each do |row|
      unless object[:cache].nil? then
        @cache = Cashier.verify row[object[:cache].to_i], object, row, object[:seed]
      else
        @cache = Cashier.verify row[0], object, row, object[:seed]
      end
      # The actual processing
      #
      if @cache[:status] == 100 then

        # add row data to payload from selectors (key => key, value => column name)
        payload = Hash.new
        JSON.parse(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
    end
  rescue Exception => e
    I2X::Slog.exception e
  end
end