Making Flight create boarding cards

To the Flight class we add a new method make_boarding_cards() which accepts a card_printer:

class Flight:

# ...

def make_boarding_cards(self, card_printer):
for passenger, seat in sorted(self._passenger_seats()):
card_printer(passenger, seat, self.number(),
self.aircraft_model())

This tells the card_printer to print each passenger, having sorted a list of passenger-seat tuples obtained from a _passenger_seats() implementation detail method (note the leading underscore). This method is in fact a generator function which searches all seats for occupants, yielding the passenger and the seat number as they are found:

def _passenger_seats(self):
"""An iterable series of passenger seating allocations."""
row_numbers, seat_letters = self._aircraft.seating_plan()
for row in row_numbers:
for letter in seat_letters:
passenger = self._seating[row][letter]
if passenger is not None:
yield (passenger, "{}{}".format(row, letter))

Now if we run this on the REPL, we can see that the new boarding card printing system works:

>>> from airtravel import console_card_printer, make_flight
>>> f = make_flight()
>>> f.make_boarding_cards(console_card_printer)
+--------------------------------------------------------------------+
| |
|Name: Anders Hejlsberg Flight: BA758 Seat: 15E Aircraft:Airbus A319 |
| |
+--------------------------------------------------------------------+

+--------------------------------------------------------------------+
| |
| Name:Bjarne Stroustrup Flight:BA758 Seat:15F Aircraft:Airbus A319 |
| |
+--------------------------------------------------------------------+

+--------------------------------------------------------------------+
| |
| Name:Guido van Rossum Flight:BA758 Seat:12A Aircraft:Airbus A319 |
| |
+--------------------------------------------------------------------+

+--------------------------------------------------------------------+
| |
| Name:John McCarthy Flight:BA758 Seat:1C Aircraft:Airbus A319 |
| |
+--------------------------------------------------------------------+

+--------------------------------------------------------------------+
| |
| Name: Richard Hickey Flight: BA758 Seat: 1D Aircraft: Airbus A319 |
| |
+--------------------------------------------------------------------+
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset