Class: RETS4R::ListingMapper
- Inherits:
-
Object
- Object
- RETS4R::ListingMapper
- Defined in:
- lib/rets4r/listing_mapper.rb
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ ListingMapper
constructor
A new instance of ListingMapper.
- #map(original) ⇒ Object
- #reverse_map(listing_attributes) ⇒ Object
- #select ⇒ Object
- #to_dmql(listing_attributes) ⇒ Object
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 |
#select ⇒ Object
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 |