Class: MLB::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/mlb/player.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Player

Returns a new instance of Player.



5
6
7
8
9
# File 'lib/mlb/player.rb', line 5

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

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/mlb/player.rb', line 3

def from
  @from
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/mlb/player.rb', line 3

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/mlb/player.rb', line 3

def number
  @number
end

#positionsObject (readonly)

Returns the value of attribute positions.



3
4
5
# File 'lib/mlb/player.rb', line 3

def positions
  @positions
end

#toObject (readonly)

Returns the value of attribute to.



3
4
5
# File 'lib/mlb/player.rb', line 3

def to
  @to
end

Class Method Details

.all_from_roster(players) ⇒ Object

Returns an array of Player objects given a team roster



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mlb/player.rb', line 12

def self.all_from_roster(players)
  players.select { |player| player['to'].nil? }.map do |player|
    new(
      :name      => player['player'],
      :number    => player['number'].to_i,
      :positions => player['position'],
      :from      => player['from'].to_i,
      :to        => 'Present'
    )
  end
end