Module: Printing

Included in:
Caltrain, Schedule
Defined in:
lib/caltrain/printing.rb

Instance Method Summary collapse

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


2
3
4
5
6
7
8
# File 'lib/caltrain/printing.rb', line 2

def print_trip(trip, time, options={})
  start = options[:starting_at]
  output = options[: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