Class: Routing::GeoPoint

Inherits:
Struct
  • Object
show all
Defined in:
lib/routing/geo_point.rb

Overview

A GeoPoint object is a very simple representation of a geospatial point that is part of a route or can be used as base to create one.

It holds the most basic textual and geospatial information that is necessary to describe a section of a route.

The complete roundtrip from a Routing object through the Middleware to a Adapter and back uses arrays of GeoPoint objects as arguments.

Depending on your very own use-case, you can either extend the GeoPoint class or use another class that mimicks the behavior of GeoPoint. In fact, this is just a container class which is no hard requirement in general. If you decide to roll your own Adapter, Parser and maybe Middleware, you could replace the class completely

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ GeoPoint

Creates a new GeoPoint instance.

Parameters:

  • attributes (Hash) (defaults to: {})

    Automatically sets values for the attributes that match the keys of the hash.



23
24
25
26
27
# File 'lib/routing/geo_point.rb', line 23

def initialize(attributes = {})
  attributes.each do |attribute, value|
    self[attribute] = value if members.include?(attribute)
  end
end

Instance Attribute Details

#distanceObject

Returns the value of attribute distance

Returns:

  • (Object)

    the current value of distance



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def distance
  @distance
end

#latObject

Returns the value of attribute lat

Returns:

  • (Object)

    the current value of lat



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def lat
  @lat
end

#lngObject

Returns the value of attribute lng

Returns:

  • (Object)

    the current value of lng



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def lng
  @lng
end

#original_latObject

Returns the value of attribute original_lat

Returns:

  • (Object)

    the current value of original_lat



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def original_lat
  @original_lat
end

#original_lngObject

Returns the value of attribute original_lng

Returns:

  • (Object)

    the current value of original_lng



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def original_lng
  @original_lng
end

#relative_timeObject

Returns the value of attribute relative_time

Returns:

  • (Object)

    the current value of relative_time



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def relative_time
  @relative_time
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def type
  @type
end

#waypointObject

Returns the value of attribute waypoint

Returns:

  • (Object)

    the current value of waypoint



17
18
19
# File 'lib/routing/geo_point.rb', line 17

def waypoint
  @waypoint
end

Instance Method Details

#fetch(key, *args) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/routing/geo_point.rb', line 33

def fetch(key, *args)
  raise ArgumentError, "wrong number of arguments (#{args.length + 1} for 1..2)" if args.length > 1

  case key
  when *self.class.members
    send(key)
  else
    return yield(key) if block_given?
    return args.first unless args.empty?
    raise KeyError, "key #{key} not found"
  end
end

#waypoint?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/routing/geo_point.rb', line 29

def waypoint?
  !!waypoint
end