Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'comma-floats'

* comma-floats:
  Bump version to 0.1.4
  Understand floats with commas in them
  • Loading branch information...
commit c9638fd1556faae30a8052b939685b6188418eef 2 parents 47e20aa + 9812cee
Jesse Reiss authored Jesse Reiss committed
Showing with 17 additions and 13 deletions.
  1. +10 −6 lib/rack/geo.rb
  2. +1 −1  lib/rack/geo/version.rb
  3. +6 −6 spec/rack/geo_spec.rb
View
16 lib/rack/geo.rb
@@ -20,9 +20,9 @@ def initialize(value=nil)
end
MATCH_LLA = /\A([+-]?[0-9\.]+);([+-]?[0-9\.]+)(?:;([+-]?[0-9\.]+))?/.freeze
- MATCH_EPU = /\sepu=([0-9\.]+)(?:\s|\z)/i.freeze
- MATCH_HDN = /\shdn=([0-9\.]+)(?:\s|\z)/i.freeze
- MATCH_SPD = /\sspd=([0-9\.]+)(?:\s|\z)/i.freeze
+ MATCH_EPU = /\sepu=([0-9\.\,]+)(?:\s|\z)/i.freeze
+ MATCH_HDN = /\shdn=([0-9\.\,]+)(?:\s|\z)/i.freeze
+ MATCH_SPD = /\sspd=([0-9\.\,]+)(?:\s|\z)/i.freeze
# Parse Geo-Position header:
# http://tools.ietf.org/html/draft-daviel-http-geo-header-05
@@ -37,15 +37,15 @@ def parse!(value)
end
if epu = MATCH_EPU.match(value)
- @uncertainty = epu[1].to_f
+ @uncertainty = cast_as_float(epu[1])
end
if hdn = MATCH_HDN.match(value)
- @heading = hdn[1].to_f
+ @heading = cast_as_float(hdn[1])
end
if spd = MATCH_SPD.match(value)
- @speed = spd[1].to_f
+ @speed = cast_as_float(spd[1])
end
nil
@@ -86,6 +86,10 @@ def self.from_http_header(value)
private
+ def cast_as_float(value)
+ value.gsub(',', '').to_f
+ end
+
def reset!
@latitude = @longitude = @altitude = @uncertainty = @heading = @speed = nil
end
View
2  lib/rack/geo/version.rb
@@ -3,7 +3,7 @@ class Geo
module VERSION #:nodoc:
MAJOR = 0
MINOR = 1
- TINY = 3
+ TINY = 4
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
12 spec/rack/geo_spec.rb
@@ -50,9 +50,9 @@ def setup_request(header_name="HTTP_GEO_POSITION")
LATITUDES = %w[-90 -45 0 45 +45 90 +90 45.123456789]
LONGITUDES = %w[-180 -90 -45 0 45 +45 90 +90 180 +180 120.123456789]
ALTITUDES = %w[-85.5 -34 0 15 1337 8848 23300.0 +23300.0]
- UNCERTAINTIES = %w[0 0.0 0.00 1.25 32.1 455 600.123]
- HEADINGS = %w[0 0.0 0.00 1.25 32.1 180 359.123 360]
- SPEEDS = %w[0 0.0 0.00 1.25 32.1 999 9999.99 12345.6456]
+ UNCERTAINTIES = %w[0 0.0 0.00 1.25 32.1 455 600.123, 1,114.12]
+ HEADINGS = %w[0 0.0 0.00 1.25 32.1 180 359.123 360, 1,200.20]
+ SPEEDS = %w[0 0.0 0.00 1.25 32.1 999 9999.99 12345.6456, 1,500.35]
describe "#new" do
it "creates an instance of #{described_class}" do
@@ -185,7 +185,7 @@ def parse!(arg)
UNCERTAINTIES.each do |uncertainty|
value = "0;0;0 epu=#{uncertainty}"
- uncertainty_f = uncertainty.to_f
+ uncertainty_f = uncertainty.gsub(',', '').to_f
it "\"#{value}\" should return a new instance with uncertainty = #{uncertainty_f}" do
@instance.parse! value
@instance.uncertainty.should == uncertainty_f
@@ -194,7 +194,7 @@ def parse!(arg)
HEADINGS.each do |heading|
value = "0;0;0 hdn=#{heading}"
- heading_f = heading.to_f
+ heading_f = heading.gsub(',', '').to_f
it "\"#{value}\" should return a new instance with heading = #{heading_f}" do
@instance.parse! value
@instance.heading.should == heading_f
@@ -203,7 +203,7 @@ def parse!(arg)
SPEEDS.each do |speed|
value = "0;0;0 spd=#{speed}"
- speed_f = speed.to_f
+ speed_f = speed.gsub(',', '').to_f
it "\"#{value}\" should return a new instance with speed = #{speed_f}" do
@instance.parse! value
@instance.speed.should == speed_f
Please sign in to comment.
Something went wrong with that request. Please try again.