Sha256: 60c6fa93d631f8364f8b0c9b14c484365931b7b60042dc1a3522a671126ff8a8

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

require 'csv'

module I2X

  # = CSVSeedReader
  #
  # Load content from CSV seed.
  #
  class CSVSeedReader < SeedReader
    ##
    # == Read
    #
    # => Load the seed data into the @objects array for processing.
    #
    def read
      begin
        CSV.new(open(@seed[:payload][:uri]), :headers => :first_row).each do |row|
          begin
            object = @help.deep_copy @agent[:payload]
            object.each_pair do |key,value|
              variables = @help.identify_variables(object[key])
              variables.each do |v|
                object[key].gsub!("%{#{v}}", row[@seed[:payload][:selectors][v].to_i])
              end
            end
            
            unless @seed[:payload][:cache].nil? then
            	object[:seed] = row[@seed[:payload][:cache].to_i]
            else
            	object[:seed] = row[0]
            end

            
            object[:identifier] = @agent.identifier
            @objects.push object
          rescue Exception => e
            
          end
        end
      rescue Exception => e
        
      end

      @objects
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
i2x-0.1.1 lib/i2x/csvseedreader.rb
i2x-0.1 lib/i2x/csvseedreader.rb
i2x-0.0.7 lib/i2x/csvseedreader.rb
i2x-0.0.6 lib/i2x/csvseedreader.rb
i2x-0.0.5 lib/i2x/csvseedreader.rb
i2x-0.0.4 lib/i2x/csvseedreader.rb
i2x-0.0.3 lib/i2x/csvseedreader.rb