Class: SabreDevStudio::Flight::Shop::Flight

Inherits:
Object
  • Object
show all
Defined in:
lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flight_segment, direction, duration) ⇒ Flight

Returns a new instance of Flight.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 87

def initialize(flight_segment, direction, duration)
  @airlines = []
  @stops = []
  @connections = []
  @direction = direction
  if direction == 'connecting'
    @duration = flight_segment['ElapsedTime']
  else
    @duration = duration
  end
  parse_data(flight_segment)
end

Instance Attribute Details

#airlinesObject (readonly)

Returns the value of attribute airlines.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def airlines
  @airlines
end

#arrival_airportObject (readonly)

Returns the value of attribute arrival_airport.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def arrival_airport
  @arrival_airport
end

#arrival_timeObject (readonly)

Returns the value of attribute arrival_time.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def arrival_time
  @arrival_time
end

#connectionsObject (readonly)

Returns the value of attribute connections.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def connections
  @connections
end

#departure_airportObject (readonly)

Returns the value of attribute departure_airport.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def departure_airport
  @departure_airport
end

#departure_timeObject (readonly)

Returns the value of attribute departure_time.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def departure_time
  @departure_time
end

#directionObject (readonly)

Returns the value of attribute direction.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def direction
  @direction
end

#durationObject (readonly)

Returns the value of attribute duration.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def duration
  @duration
end

#flight_numberObject (readonly)

Returns the value of attribute flight_number.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def flight_number
  @flight_number
end

#stopsObject (readonly)

Returns the value of attribute stops.



83
84
85
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 83

def stops
  @stops
end

Instance Method Details

#add_connecting_flight(flight) ⇒ Object



121
122
123
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 121

def add_connecting_flight(flight)
  @connections << flight.sha
end

#shaObject



100
101
102
103
104
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 100

def sha
  str = "#{@airlines.first}_#{@flight_number}_#{@departure_airport}_#{@departure_time}"
  # Digest::SHA1.hexdigest(str)
  str
end

#to_hashObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/sabre_dev_studio-flight/shop/streamlined_itineraries.rb', line 106

def to_hash
  {
    uid: sha,
    direction: @direction,
    airlines: airlines.uniq,
    duration: minutes_to_time(duration),
    departureAirport: departure_airport,
    arrivalAirport: arrival_airport,
    stops: stops,
    connections: connections,
    departureTime: reformat_date_time(departure_time),
    arrivalTime: reformat_date_time(arrival_time)
  }
end