Class: Graticule::Precision

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/graticule/precision.rb

Overview

Used to compare the precision of different geocoded locations

Constant Summary collapse

NAMES =
[
  :point,
  :unknown,
  :country,
  :region,
  :locality,
  :postal_code,
  :street,
  :address,
  :premise
]
Unknown =
Precision.new(:unknown)
Point =
Precision.new(:point)
Country =
Precision.new(:country)
Region =
Precision.new(:region)
Locality =
Precision.new(:locality)
PostalCode =
Precision.new(:postal_code)
Street =
Precision.new(:street)
Address =
Precision.new(:address)
Premise =
Precision.new(:premise)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Precision

Returns a new instance of Precision.

Raises:

  • (ArgumentError)

21
22
23
24
# File 'lib/graticule/precision.rb', line 21

def initialize(name)
  @name = name.to_sym
  raise ArgumentError, "#{name} is not a valid precision. Use one of #{NAMES.inspect}" unless NAMES.include?(@name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


7
8
9
# File 'lib/graticule/precision.rb', line 7

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object


40
41
42
43
# File 'lib/graticule/precision.rb', line 40

def <=>(other)
  other = Precision.new(other) unless other.is_a?(Precision)
  NAMES.index(self.name) <=> NAMES.index(other.name)
end

#==(other) ⇒ Object


45
46
47
# File 'lib/graticule/precision.rb', line 45

def ==(other)
  (self <=> other) == 0
end

#to_sObject


36
37
38
# File 'lib/graticule/precision.rb', line 36

def to_s
  @name.to_s
end