Sha256: e55cece29c374267e3659b98a1a8f68f789143a7c8b32be34e4691a1c3f4fe29

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

module MetraSchedule
  class Train
    attr_reader :train_num, :schedule, :bike_limit, :direction, :stops

    def initialize(options={})
      unless options.empty?
        @train_num = options[:train_num] if options.has_key?(:train_num)
        @schedule = options[:schedule] if options.has_key?(:schedule)
        @bike_limit = options[:bike_limit] if options.has_key?(:bike_limit)
        @direction = options[:direction] if options.has_key?(:direction)
        @stops = options[:stops] if options.has_key?(:stops)
      end
    end

    def has_stop?(stop)
      return true if stops.any? {|s| s.station == stop}
      false
    end

    def in_time?(station, time)
      return true if stops.find {|s| s.station == station}.time > time
      false
    end

    def departure_and_arrival(start, destination)
      departure = @stops.find {|s| s.station == start}.time
      arrival = @stops.find {|s| s.station == destination}.time
      {:departure => departure, :arrival => arrival}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
metra_schedule-0.2.1 lib/metra/train.rb