Skip to content

Commit

Permalink
Fix comparing two locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 8, 2018
1 parent ebfa929 commit f8c32b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/geospatial/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ def to_ary
to_a
end

def to_h
{latitude: @latitude, longitude: @longitude}
end

def to_s
"#{self.class}[#{self.longitude.to_f}, #{self.latitude.to_f}]"
end

include Comparable

def <=> other
to_a <=> other.to_a
end

alias inspect to_s

attr :longitude # -180 -> 180 (equivalent to x)
Expand Down
5 changes: 5 additions & 0 deletions spec/geospatial/location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
it "should format nicely" do
expect("#{lake_alex}").to be == "Geospatial::Location[170.45, -43.94]"
end

it "should have equivalence" do
expect(lake_tekapo).to be == lake_tekapo
expect(lake_alex).to_not be == lake_tekapo
end
end

context 'points on equator' do
Expand Down

0 comments on commit f8c32b6

Please sign in to comment.