Sha256: 5692ee856d414a37987a8444e99c18e535e93fb556afd688680fc0fcf80a1a7b

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 KB

Contents

class MLS::Region < MLS::Resource

  property :id,             Fixnum, :serialize => :if_present
  property :name,           String, :serialize => false
  property :proper_name,    String, :serialize => :if_present
  property :common_name,    String, :serialize => :if_present
  property :code,           String, :serialize => :if_present
  property :type,           String, :serialize => :if_present
  property :source,         String, :serialize => :if_present
  property :minimum_zoom,   Fixnum, :serialize => :if_present
  property :maximum_zoom,   Fixnum, :serialize => :if_present
  property :slug,           String, :serialize => false
  property :geometry,       Hash,   :serialize => false
  property :envelope,       Hash,   :serialize => false
  property :children,       Hash,   :serialize => false

  # Counter caches
  property :listings_count, Fixnum, :serialize => :false

  class << self

    def find(id)
      response = MLS.get("/regions/#{id}")
      MLS::Region::Parser.parse(response.body)
    end

  end

  def bounds
    return nil unless envelope
    n, e, s, w = nil, nil, nil, nil
    envelope[:coordinates][0].each do |c|
      lon, lat = *c
      n = lat if !n || lat > n
      e = lon if !e || lon > e
      s = lat if !s || lat < s
      w = lon if !w || lon < w
    end
    [n, e, s, w]
  end

end


class MLS::Region::Parser < MLS::Parser

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mls-0.8.0 lib/mls/models/region.rb
mls-0.7.2 lib/mls/models/region.rb
mls-0.7.1 lib/mls/models/region.rb
mls-0.7.0 lib/mls/models/region.rb
mls-0.6.7 lib/mls/models/region.rb
mls-0.6.6 lib/mls/models/region.rb
mls-0.6.5 lib/mls/models/region.rb
mls-0.6.4 lib/mls/models/region.rb