Class: Innards::Parsers::ParserBase

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/innards/parsers/parser_base.rb

Overview

Base Parser from which all RETS Response Parsers are based

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParserBase

Returns a new instance of ParserBase.



12
13
14
15
# File 'lib/innards/parsers/parser_base.rb', line 12

def initialize
  @switches = {}
  @metadata = {}
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/innards/parsers/parser_base.rb', line 10

def 
  @metadata
end

#rets_responseObject (readonly)

Returns the value of attribute rets_response.



10
11
12
# File 'lib/innards/parsers/parser_base.rb', line 10

def rets_response
  @rets_response
end

Instance Method Details

#attr(name, value) ⇒ Object



25
26
27
28
29
30
# File 'lib/innards/parsers/parser_base.rb', line 25

def attr(name, value)
  if switch_active?(:RETS)
    @rets_response = {} unless @rets_response.kind_of?(Hash)
    @rets_response[name] = value
  end
end

#data_merger(columns, data) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/innards/parsers/parser_base.rb', line 63

def data_merger columns, data
  merged_data = {}
  columns.each_with_index do |object, index|
    merged_data[object] = data[index] unless index == 0
  end
  merged_data
end

#data_splitter(data) ⇒ Object



59
60
61
# File 'lib/innards/parsers/parser_base.rb', line 59

def data_splitter data
  data.split(/\t/)
end

#element_tracker_switch(element, currently_in) ⇒ Object



51
52
53
# File 'lib/innards/parsers/parser_base.rb', line 51

def element_tracker_switch element, currently_in
  @switches[element] = currently_in
end

#end_element(name) ⇒ Object



21
22
23
# File 'lib/innards/parsers/parser_base.rb', line 21

def end_element(name)
  element_tracker_switch name, false
end

#response_codeObject



47
48
49
# File 'lib/innards/parsers/parser_base.rb', line 47

def response_code
  @rets_response[:ReplyCode].to_i if @rets_response.has_key?(:ReplyCode)
end

#split_multiline_key_value_pairs(value) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/innards/parsers/parser_base.rb', line 35

def split_multiline_key_value_pairs value
  result = {}
  value.scan(/(\w+) = (.*?)$/) do |match|
    result[match[0].to_sym] = match[1].gsub(/http:\/\/.+?\//, "/")
  end
  result
end

#start_element(name) ⇒ Object



17
18
19
# File 'lib/innards/parsers/parser_base.rb', line 17

def start_element(name)
  element_tracker_switch name, true
end

#switch_active?(element) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/innards/parsers/parser_base.rb', line 55

def switch_active? element
  (@switches[element] == true)
end

#text(value) ⇒ Object



32
33
# File 'lib/innards/parsers/parser_base.rb', line 32

def text(value)
end

#valid_rets_response_received?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/innards/parsers/parser_base.rb', line 43

def valid_rets_response_received?
  response_code == 0
end