Class: Geogov::FuzzyPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/geogov/fuzzy_point.rb

Constant Summary collapse

ACCURACIES =
[:point,:postcode,:postcode_district,:ward,:council,:nation,:country,:planet]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat, lon, accuracy) ⇒ FuzzyPoint

Returns a new instance of FuzzyPoint.

Raises:

  • (ValueError)


8
9
10
11
12
13
14
15
16
# File 'lib/geogov/fuzzy_point.rb', line 8

def initialize(lat,lon,accuracy)
  accuracy = accuracy.to_sym
  raise ValueError unless ACCURACIES.include?(accuracy)
  @lon,@lat,@accuracy = lon.to_f, lat.to_f, accuracy
  if @accuracy == :point
    @lon = @lon.round(2)
    @lat = @lat.round(2)
  end
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



5
6
7
# File 'lib/geogov/fuzzy_point.rb', line 5

def accuracy
  @accuracy
end

#latObject (readonly)

Returns the value of attribute lat.



5
6
7
# File 'lib/geogov/fuzzy_point.rb', line 5

def lat
  @lat
end

#lonObject (readonly)

Returns the value of attribute lon.



5
6
7
# File 'lib/geogov/fuzzy_point.rb', line 5

def lon
  @lon
end

Instance Method Details

#to_hashObject



18
19
20
# File 'lib/geogov/fuzzy_point.rb', line 18

def to_hash
  {"lon"=> self.lon.to_s,"lat"=>self.lat.to_s,"accuracy"=>accuracy.to_s}
end