Skip to content

Commit

Permalink
Add optional decimal_places param to distance_in_miles
Browse files Browse the repository at this point in the history
  • Loading branch information
unikitty37 committed Feb 16, 2017
1 parent c6ff624 commit 6fd004a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion google_directions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Gem::Specification.new do |s|
s.name = "google_directions"
s.version = "0.1.6.2"
s.version = "0.1.6.3"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
Expand Down
4 changes: 2 additions & 2 deletions lib/google_directions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def distance_text
end
end

def distance_in_miles
def distance_in_miles(decimal_places: 0)
if @status != "OK"
distance_in_miles = 0
else
meters = distance
distance_in_miles = (meters.to_f / 1610.22).round
distance_in_miles = (meters.to_f / 1610.22).round(decimal_places)
distance_in_miles
end
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/google_directions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_happy_case
dest = "499 Gordonsville Highway, 38563"
directions = GoogleDirections.new(orig, dest)
assert_equal(4, directions.distance_in_miles)
assert_equal(3.6, directions.distance_in_miles(decimal_places: 1))
assert_equal(5, directions.drive_time_in_minutes)
assert_equal('http://maps.googleapis.com/maps/api/directions/xml?language=en&alternative=true&sensor=false&mode=driving&origin=121+Gordonsville+Highway%2C+37030&destination=499+Gordonsville+Highway%2C+38563', directions.xml_call)
# end_location > lat
Expand Down

0 comments on commit 6fd004a

Please sign in to comment.