Class: GoogleMapsAPI::DistanceMatrix::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/google_maps_api/distance_matrix/element.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, duration = nil, distance = nil) ⇒ Element

Returns a new instance of Element.



4
5
6
7
8
# File 'lib/google_maps_api/distance_matrix/element.rb', line 4

def initialize(status, duration = nil, distance = nil)
  @status = status
  @duration = duration
  @distance = distance
end

Instance Attribute Details

#distanceObject (readonly)

Returns the value of attribute distance.



2
3
4
# File 'lib/google_maps_api/distance_matrix/element.rb', line 2

def distance
  @distance
end

#durationObject (readonly)

Returns the value of attribute duration.



2
3
4
# File 'lib/google_maps_api/distance_matrix/element.rb', line 2

def duration
  @duration
end

#statusObject (readonly)

Returns the value of attribute status.



2
3
4
# File 'lib/google_maps_api/distance_matrix/element.rb', line 2

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/google_maps_api/distance_matrix/element.rb', line 10

def self.from_hash(hash)
  if hash["status"] == "OK"
    new(
      hash["status"],
      GoogleMapsAPI::Core::Duration.from_hash(hash["duration"]),
      GoogleMapsAPI::Core::Distance.from_hash(hash["distance"])
    )
  else
    new(hash["status"])
  end
end