Sha256: 373b64f081c4f947890366b956388a3168f7207499b238ba5805a83cd6dd020f

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

module ARII

  # = XMLSeedReader
  #
  # Load content from XML seed.
  #
  class XMLSeedReader < SeedReader
    ##
    # == Read
    #
    # => Load the seed data into the @objects array for processing.
    #
    def read
      begin
        @doc = Nokogiri::XML(open(@seed[:payload][:uri]))
        @doc.remove_namespaces!
        @doc.xpath(@seed[:payload][:query]).each do |element|
          begin
            object = @help.deep_copy @agent[:payload]
            object.each_pair do |key, value|
              variables = @help.identify_variables(object[key])
              variables.each do |v|
                element.xpath(@seed[:payload][:selectors][v]).each do |el|
                  object[key].gsub!("%{#{v}}", el.content)
                end
              end
            end

            unless @seed[:payload][:cache].nil? then
              element.xpath(@seed[:payload][:cache]).each do |el|
                object[:seed] = el.content
              end
            else
              element.xpath('id').each do |el|
                object[:seed] = el.content
              end
            end

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

          end
        end
      rescue Exception => e

      end

      @objects
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arii-1.8 lib/arii/xmlseedreader.rb
arii-1.7 lib/arii/xmlseedreader.rb
arii-1.6 lib/arii/xmlseedreader.rb
arii-1.5 lib/arii/xmlseedreader.rb
arii-1.2.2 lib/arii/xmlseedreader.rb