Class: ServerSideGoogleMaps::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/server-side-google-maps/route.rb

Instance Method Summary collapse

Constructor Details

#initialize(points, params = {}) ⇒ Route

Returns a new instance of Route.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
# File 'lib/server-side-google-maps/route.rb', line 3

def initialize(points, params = {})
  raise ArgumentError if points.length < 2

  @directionses = points[0..-2].zip(points[1..-1]).map do |origin, destination|
    Directions.new(origin, destination, params)
  end
end

Instance Method Details

#destination_addressObject



23
24
25
# File 'lib/server-side-google-maps/route.rb', line 23

def destination_address
  @directionses.last.destination_address
end

#destination_inputObject



15
16
17
# File 'lib/server-side-google-maps/route.rb', line 15

def destination_input
  @directionses.last.destination_input
end

#destination_pointObject



31
32
33
# File 'lib/server-side-google-maps/route.rb', line 31

def destination_point
  @directionses.last.destination_point
end

#distanceObject



39
40
41
# File 'lib/server-side-google-maps/route.rb', line 39

def distance
  @distance ||= @directionses.map{|d| d.distance}.inject(:+)
end

#origin_addressObject



19
20
21
# File 'lib/server-side-google-maps/route.rb', line 19

def origin_address
  @directionses.first.origin_address
end

#origin_inputObject



11
12
13
# File 'lib/server-side-google-maps/route.rb', line 11

def origin_input
  @directionses.first.origin_input
end

#origin_pointObject



27
28
29
# File 'lib/server-side-google-maps/route.rb', line 27

def origin_point
  @directionses.first.origin_point
end

#pathObject



35
36
37
# File 'lib/server-side-google-maps/route.rb', line 35

def path
  Path.new(points)
end