short form
[ottawa-travel-planner.git] / ShortFormatter.py
blob7906c4e71cee0767c5d60ed2f2a460a29794843d
2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
4 """Formats an Itinerary for terse display."""
6 import Itinerary
8 class ShortFormatter:
9 def __init__(self, itinentries):
10 self.entries = itinentries
12 # A list of text strings to display.
13 self.lines = []
15 self.format()
17 def format(self):
18 for ie in self.entries:
19 if ie.type == Itinerary.TYPE_WALK_TO_STOP:
20 self.formatWalkToStop(ie)
21 elif ie.type == Itinerary.TYPE_TAKE_BUS:
22 self.formatTakeBus(ie)
24 def formatWalkToStop(self, ie):
25 line = "-%s walk to %s (%s)" \
26 % (ie.startTime, ie.destination, ie.busStop)
27 self.lines.append(line)
29 def formatTakeBus(self, ie):
30 line = "-%s %s %s to %s at %s" \
31 % (ie.startTime, ie.route, ie.direction,
32 ie.destination, ie.endTime)
33 self.lines.append(line)
35 def __str__(self):
36 return "\n".join(self.lines)
38 def __repr__(self):
39 print self.__str__()