Class: ARII::CSVDetector
Overview
CSVDetector
Detect changes in CSV files (using column numbers).
Instance Attribute Summary
Attributes inherited from Detector
#agent, #content, #identifier, #objects, #payloads, #templates
Instance Method Summary collapse
-
#detect(object) ⇒ Object
Detect the changes.
Methods inherited from Detector
Constructor Details
This class inherits a constructor from ARII::Detector
Instance Method Details
#detect(object) ⇒ Object
Detect the changes
17 18 19 20 21 22 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 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arii/csvdetector.rb', line 17 def detect object ARII::Config.log.debug(self.class.name) { "Monitoring #{object[:uri]}" } CSV.new(open(object[:uri]), :headers => :first_row).each do |row| begin unless object[:cache].nil? then @response = Cashier.verify row[object[:cache].to_i], object, row, object[:seed] else @response = Cashier.verify row[0], object, row, object[:seed] end rescue Exception => e ARII::Config.log.error(self.class.name) { "Loading error: #{e}" } end begin # Process ARIIcache response @cache = JSON.parse(@response, {:symbolize_names => true}) unless @cache[:templates].nil? then @cache[:templates].each do |t| @templates.push t end end # The actual processing # if @cache[:cache][:status] == 100 then ARII::Config.log.info(self.class.name) { "Not on cache, generating payload" } 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 ARII::Config.log.error(self.class.name) { "Processing error: #{e}" } end @cache[:templates] end end |