Class: MiamiDadeGeo::Coordinate

Inherits:
Object
  • Object
show all
Defined in:
lib/miami_dade_geo/coordinate.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Coordinate

Returns a new instance of Coordinate.



6
7
8
9
10
11
12
13
14
15
# File 'lib/miami_dade_geo/coordinate.rb', line 6

def initialize(opts)
  if opts[:x] && opts[:y]
    initialize_from_xy opts
  elsif
    opts[:lat] && opts[:long]
    initialize_from_latlong opts
  else
    fail ArgumentError "Can't initialize without x & y or lat & long"
  end
end

Instance Method Details

#addressObject



59
60
61
62
63
64
# File 'lib/miami_dade_geo/coordinate.rb', line 59

def address
  return @address if defined? @address
  feature = get_closest_feature_client.find_feature(xy, 'GeoAddress')

  @address = Address.new_from_feature feature
end

#initialize_from_latlong(opts) ⇒ Object



22
23
24
25
# File 'lib/miami_dade_geo/coordinate.rb', line 22

def initialize_from_latlong(opts)
  @lat = opts[:lat].to_f
  @long = opts[:long].to_f
end

#initialize_from_xy(opts) ⇒ Object



17
18
19
20
# File 'lib/miami_dade_geo/coordinate.rb', line 17

def initialize_from_xy(opts)
  @x = opts[:x].to_f
  @y = opts[:y].to_f
end

#latObject



39
40
41
42
43
# File 'lib/miami_dade_geo/coordinate.rb', line 39

def lat
  return @lat if @lat
  load_latlong_from_xy
  @lat
end

#latlongObject



55
56
57
# File 'lib/miami_dade_geo/coordinate.rb', line 55

def latlong
  {  lat: lat, long: long }
end

#longObject



45
46
47
48
49
# File 'lib/miami_dade_geo/coordinate.rb', line 45

def long
  return @long if @long
  load_latlong_from_xy
  @long
end

#xObject



27
28
29
30
31
# File 'lib/miami_dade_geo/coordinate.rb', line 27

def x
  return @x if @x
  load_xy_from_latlong
  @x
end

#xyObject



51
52
53
# File 'lib/miami_dade_geo/coordinate.rb', line 51

def xy
  { x: x, y: y }
end

#yObject



33
34
35
36
37
# File 'lib/miami_dade_geo/coordinate.rb', line 33

def y
  return @y if @y
  load_xy_from_latlong
  @y
end