Sha256: cf2a5ef4faea6338dfa5e4ff358bdb05334a8eed05fa082d647d79fc54e3a582

Contents?: true

Size: 952 Bytes

Versions: 4

Compression:

Stored size: 952 Bytes

Contents

# Parses XML response containing 'COMPACT' data format.

require 'cgi'

module RETS4R
  class Client
    class CompactDataParser
      def parse_results(doc)

        delimiter = doc.get_elements('/RETS/DELIMITER')[0].attributes['value'].to_i.chr
        columns   = doc.get_elements('/RETS/COLUMNS')[0]
        rows      = doc.get_elements('/RETS/DATA')

        parse_data(columns, rows, delimiter)
      end

      def parse_data(column_element, row_elements, delimiter = "\t")

        column_names = column_element.text.split(delimiter)

        result = []

        data = row_elements.each do |data_row|
          data_row = data_row.text.split(delimiter)

          row_result = {}

          column_names.each_with_index do |col, x|
            row_result[col] = data_row[x]
          end

          row_result.reject! { |k,v| k.nil? || k.empty? }

          result << row_result
        end

        return result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
josephholsten-rets4r-1.1.16 lib/rets4r/client/parsers/compact.rb
josephholsten-rets4r-1.1.15 lib/rets4r/client/parsers/compact.rb
josephholsten-rets4r-1.1.14 lib/rets4r/client/parsers/compact.rb
josephholsten-rets4r-1.1.13 lib/rets4r/client/parsers/compact.rb