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
23 24 25 26 27 28 29 |
# File 'lib/caltrain/printing.rb', line 23 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 9 10 11 12 |
# File 'lib/caltrain/printing.rb', line 2 def print_trip(trip, time, ={}) start = [:starting_at] output = [:output] || $stdout detailed = ([:detailed] == true) output << train_info(trip, time) << "\n" if detailed output << " " << stop_info(trip, start) << "\n" end end |
#stop_info(trip, start = trip.stops.first) ⇒ Object
18 19 20 21 |
# File 'lib/caltrain/printing.rb', line 18 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
14 15 16 |
# File 'lib/caltrain/printing.rb', line 14 def train_info(trip, time) "#{time} - Train #{trip.train_no} (#{trip.type})" end |