Permalink
Browse files

Adding bounds to the region model.

  • Loading branch information...
1 parent 362b34e commit 8a550326cc365fb78e9d61e042f3005ca191e1f1 @waratuman waratuman committed Apr 23, 2013
Showing with 17 additions and 4 deletions.
  1. +16 −3 lib/mls/models/region.rb
  2. +1 −1 mls.gemspec
@@ -13,17 +13,30 @@ class MLS::Region < MLS::Resource
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
View
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "mls"
- s.version = '0.2.46'
+ s.version = '0.2.47'
s.authors = ["James R. Bracy", "Jon Bracy"]
s.email = ["james@42floors.com"]
s.homepage = "http://mls.42floors.com"

0 comments on commit 8a55032

Please sign in to comment.