Class: RETS4R::ResponseDocument::Search

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rets4r/response_document/search.rb

Overview

search response document. slower than sax, but easier to play with.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#count, #error?, #invalid?, #max_rows?, #parse_count, #parse_key_value, #parse_results, #reply_code, #reply_text, #rets?, safe_parse, #success?, #to_h, #to_rexml, #valid?, #validate!

Class Method Details

.row_to_hash(string, headers, delimiter) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/rets4r/response_document/search.rb', line 39

def self.row_to_hash(string, headers, delimiter)
  items = string.split(delimiter)  # compact always begins with a field delimiter, we can drop it

  items = items[1..-1]
  pairs = headers.zip(items).reject {|k,v| k.empty? }
  Hash[pairs]
end

.split_raw_headers(string, delimiter) ⇒ Object


34
35
36
37
# File 'lib/rets4r/response_document/search.rb', line 34

def self.split_raw_headers(string, delimiter)
  # compact always begins with a field delimiter, we can drop it
  string.split(delimiter)[1..-1]
end

Instance Method Details

#delimiterObject Also known as: ascii_delimiter

returns the column delimiter as an ASCII string

Example Search.parse('<RETS><DELIMITER value=“09” /></RETS>).delimiter

> “t”


14
15
16
# File 'lib/rets4r/response_document/search.rb', line 14

def delimiter
  at('/RETS/DELIMITER')['value'].to_i.chr
end

#eachObject

:yields: row


24
25
26
# File 'lib/rets4r/response_document/search.rb', line 24

def each #:yields: row
  each_raw_row {|row| yield row_to_hash(row) }
end

#headersObject Also known as: columns


19
20
21
# File 'lib/rets4r/response_document/search.rb', line 19

def headers
  split_raw_headers(at('/RETS/COLUMNS').text)
end

#to_transactionObject


30
31
32
# File 'lib/rets4r/response_document/search.rb', line 30

def to_transaction
  super { to_a }
end