Sha256: 605d7ef4d7c5f1cd3c51dad8bffed782099e00939915dced234179343de5d7cd

Contents?: true

Size: 577 Bytes

Versions: 7

Compression:

Stored size: 577 Bytes

Contents

module MLB
  class Player
    private_class_method :new
    attr_reader :name, :number, :position

    private

    def initialize(attributes={})
      attributes.each_pair do |key, value|
        instance_eval("@#{key}=value") if self.respond_to?(key)
      end
    end

    # Returns an array of Player objects given a team roster
    def self.all_from_roster(players)
      players.map do |player|
        new(
          :name     => player['player'],
          :number   => player['number'],
          :position => player['position']
        )
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mlb-0.5.5 lib/mlb/player.rb
mlb-0.5.4 lib/mlb/player.rb
mlb-0.5.3 lib/mlb/player.rb
mlb-0.5.2 lib/mlb/player.rb
mlb-0.5.1 lib/mlb/player.rb
mlb-0.5.0 lib/mlb/player.rb
mlb-0.4.0 lib/mlb/player.rb