Sha256: 64a1890d6c0de0969079165a766ecd50c8847bf2d43bc0ad69669f30d1702aba

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

module Dyno
  class Competitor
    attr_accessor :name, :uid, :position, :vehicle, :laps, :race_time,
      :best_lap, :lap_times

    ##
    # @param [String] name The competitor's name.
    # @param [Hash]   properties Extra information about the competitor.
    #
    def initialize(name, properties = {})
      @name = name
      @lap_times = properties.fetch(:laps, [])
      @dnf = false

      [:uid, :position, :vehicle, :laps, :race_time, :best_lap].each do |prop|
        instance_variable_set "@#{prop}", properties[prop]
      end
    end

    ##
    # Returns true fi the competitor finished the event.
    #
    def finished?
      not dnf? and not dsq?
    end

    ##
    # Flags this competitor as having not completed the event.
    #
    def dnf!
      @dnf = :dnf
    end

    ##
    # Returns true if the competitor failed to finish.
    #
    def dnf?
      @dnf == :dnf
    end

    ##
    # Flags this competitor has having been disqualified from the event.
    #
    def dsq!
      @dnf = :dsq
    end

    ##
    # Returns true if the competitor was disqualified.
    #
    def dsq?
      @dnf == :dsq
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
anthonyw-dyno-0.1.0 lib/dyno/competitor.rb
anthonyw-dyno-0.1.1 lib/dyno/competitor.rb
antw-dyno-0.1.2 lib/dyno/competitor.rb
antw-dyno-0.1.3 lib/dyno/competitor.rb