Class: GoogleMapsPlatform::DirectionsTransitDetails

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/directions_transit_details.rb

Overview

Additional information that is not relevant for other modes of transportation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(arrival_stop: SKIP, arrival_time: SKIP, departure_stop: SKIP, departure_time: SKIP, headsign: SKIP, headway: SKIP, line: SKIP, num_stops: SKIP, trip_short_name: SKIP, additional_properties: nil) ⇒ DirectionsTransitDetails

Returns a new instance of DirectionsTransitDetails.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 99

def initialize(arrival_stop: SKIP, arrival_time: SKIP, departure_stop: SKIP,
               departure_time: SKIP, headsign: SKIP, headway: SKIP,
               line: SKIP, num_stops: SKIP, trip_short_name: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @arrival_stop = arrival_stop unless arrival_stop == SKIP
  @arrival_time = arrival_time unless arrival_time == SKIP
  @departure_stop = departure_stop unless departure_stop == SKIP
  @departure_time = departure_time unless departure_time == SKIP
  @headsign = headsign unless headsign == SKIP
  @headway = headway unless headway == SKIP
  @line = line unless line == SKIP
  @num_stops = num_stops unless num_stops == SKIP
  @trip_short_name = trip_short_name unless trip_short_name == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#arrival_stopDirectionsTransitStop

TODO: Write general description for this method



15
16
17
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 15

def arrival_stop
  @arrival_stop
end

#arrival_timeTimeZoneTextValueObject

An object containing Unix time, a time zone, and its formatted text representation.



20
21
22
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 20

def arrival_time
  @arrival_time
end

#departure_stopDirectionsTransitStop

An object containing Unix time, a time zone, and its formatted text representation.



25
26
27
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 25

def departure_stop
  @departure_stop
end

#departure_timeTimeZoneTextValueObject

An object containing Unix time, a time zone, and its formatted text representation.



30
31
32
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 30

def departure_time
  @departure_time
end

#headsignString

Specifies the direction in which to travel on this line, as it is marked on the vehicle or at the departure stop. This will often be the terminus station.

Returns:

  • (String)


36
37
38
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 36

def headsign
  @headsign
end

#headwayInteger

Specifies the expected number of seconds between departures from the same stop at this time. For example, with a headway value of 600, you would expect a ten minute wait if you should miss your bus.

Returns:

  • (Integer)


42
43
44
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 42

def headway
  @headway
end

#lineDirectionsTransitLine

Specifies the expected number of seconds between departures from the same stop at this time. For example, with a headway value of 600, you would expect a ten minute wait if you should miss your bus.



48
49
50
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 48

def line
  @line
end

#num_stopsInteger

The number of stops from the departure to the arrival stop. This includes the arrival stop, but not the departure stop. For example, if your directions involve leaving from Stop A, passing through stops B and C, and arriving at stop D, num_stops will return 3.

Returns:

  • (Integer)


55
56
57
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 55

def num_stops
  @num_stops
end

#trip_short_nameString

The text that appears in schedules and sign boards to identify a transit trip to passengers. The text should uniquely identify a trip within a service day. For example, “538” is the trip_short_name of the Amtrak train that leaves San Jose, CA at 15:10 on weekdays to Sacramento, CA.

Returns:

  • (String)


62
63
64
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 62

def trip_short_name
  @trip_short_name
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 119

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  arrival_stop = DirectionsTransitStop.from_hash(hash['arrival_stop']) if hash['arrival_stop']
  arrival_time = TimeZoneTextValueObject.from_hash(hash['arrival_time']) if
    hash['arrival_time']
  departure_stop = DirectionsTransitStop.from_hash(hash['departure_stop']) if
    hash['departure_stop']
  departure_time = TimeZoneTextValueObject.from_hash(hash['departure_time']) if
    hash['departure_time']
  headsign = hash.key?('headsign') ? hash['headsign'] : SKIP
  headway = hash.key?('headway') ? hash['headway'] : SKIP
  line = DirectionsTransitLine.from_hash(hash['line']) if hash['line']
  num_stops = hash.key?('num_stops') ? hash['num_stops'] : SKIP
  trip_short_name =
    hash.key?('trip_short_name') ? hash['trip_short_name'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  DirectionsTransitDetails.new(arrival_stop: arrival_stop,
                               arrival_time: arrival_time,
                               departure_stop: departure_stop,
                               departure_time: departure_time,
                               headsign: headsign,
                               headway: headway,
                               line: line,
                               num_stops: num_stops,
                               trip_short_name: trip_short_name,
                               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 65

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['arrival_stop'] = 'arrival_stop'
  @_hash['arrival_time'] = 'arrival_time'
  @_hash['departure_stop'] = 'departure_stop'
  @_hash['departure_time'] = 'departure_time'
  @_hash['headsign'] = 'headsign'
  @_hash['headway'] = 'headway'
  @_hash['line'] = 'line'
  @_hash['num_stops'] = 'num_stops'
  @_hash['trip_short_name'] = 'trip_short_name'
  @_hash
end

.nullablesObject

An array for nullable fields



95
96
97
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 95

def self.nullables
  []
end

.optionalsObject

An array for optional fields



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 80

def self.optionals
  %w[
    arrival_stop
    arrival_time
    departure_stop
    departure_time
    headsign
    headway
    line
    num_stops
    trip_short_name
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



167
168
169
170
171
172
173
174
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 167

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} arrival_stop: #{@arrival_stop.inspect}, arrival_time:"\
  " #{@arrival_time.inspect}, departure_stop: #{@departure_stop.inspect}, departure_time:"\
  " #{@departure_time.inspect}, headsign: #{@headsign.inspect}, headway: #{@headway.inspect},"\
  " line: #{@line.inspect}, num_stops: #{@num_stops.inspect}, trip_short_name:"\
  " #{@trip_short_name.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



158
159
160
161
162
163
164
# File 'lib/google_maps_platform/models/directions_transit_details.rb', line 158

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} arrival_stop: #{@arrival_stop}, arrival_time: #{@arrival_time},"\
  " departure_stop: #{@departure_stop}, departure_time: #{@departure_time}, headsign:"\
  " #{@headsign}, headway: #{@headway}, line: #{@line}, num_stops: #{@num_stops},"\
  " trip_short_name: #{@trip_short_name}, additional_properties: #{@additional_properties}>"
end