Module: Printing

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

Instance Method Summary collapse

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


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

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