Module: Printing
Instance Method Summary collapse
- #pretty_hash(hash) ⇒ Object
- #print_trip(trip, time, options = {}) ⇒ Object
- #stop_info(trip, start = trip.stops.first) ⇒ Object
- #train_info(trip, time) ⇒ Object
Instance Method Details
#pretty_hash(hash) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/caltrain/printing.rb', line 19 def pretty_hash(hash) max_field_width = hash.values.map(&:size).max hash.each do |key, value| puts "%#{max_field_width}s #{key}" % value end end |
#print_trip(trip, time, options = {}) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/caltrain/printing.rb', line 2 def print_trip(trip, time, ={}) start = [:starting_at] output = [:output] || $stdout output << train_info(trip, time) << "\n" output << " " << stop_info(trip, start) << "\n" end |
#stop_info(trip, start = trip.stops.first) ⇒ Object
14 15 16 17 |
# File 'lib/caltrain/printing.rb', line 14 def stop_info(trip, start=trip.stops.first) string = trip.stops.join(' -> ') "*#{string[(string =~ /\b#{start}\b/ || 0)..-1]}" end |
#train_info(trip, time) ⇒ Object
10 11 12 |
# File 'lib/caltrain/printing.rb', line 10 def train_info(trip, time) "#{time} - Train #{trip.train_no} (#{trip.type})" end |