Class: RETS4R::ListingMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rets4r/listing_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ListingMapper

Returns a new instance of ListingMapper.


3
4
5
# File 'lib/rets4r/listing_mapper.rb', line 3

def initialize(params = {})
  @select = params[:select] || ListingService.connection[:select]
end

Instance Method Details

#map(original) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/rets4r/listing_mapper.rb', line 9

def map(original)
  listing = {}
  @select.each_pair {|rets_key, record_key|
    listing[record_key] = original[rets_key]
  }
  listing
end

#reverse_map(listing_attributes) ⇒ Object


21
22
23
24
25
# File 'lib/rets4r/listing_mapper.rb', line 21

def reverse_map(listing_attributes)
  select.inject({}) do |hash,(k,v)|
    hash.tap { |h| h[k] = listing_attributes[v] if listing_attributes[v] }
  end
end

#selectObject


6
7
8
# File 'lib/rets4r/listing_mapper.rb', line 6

def select
  @select
end

#to_dmql(listing_attributes) ⇒ Object


16
17
18
19
20
# File 'lib/rets4r/listing_mapper.rb', line 16

def to_dmql(listing_attributes)
  reverse_map(listing_attributes).map do |k,v|
    %[(#{k.to_sym}=#{field_encode_value(v)})]
  end.join(',')
end