Class: MLB::Player
- Inherits:
-
Object
- Object
- MLB::Player
- Defined in:
- lib/mlb/player.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#positions ⇒ Object
readonly
Returns the value of attribute positions.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
-
.all_from_roster(players) ⇒ Object
Returns an array of Player objects given a team roster.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Player
constructor
A new instance of Player.
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
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/mlb/player.rb', line 3 def from @from end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/mlb/player.rb', line 3 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/mlb/player.rb', line 3 def number @number end |
#positions ⇒ Object (readonly)
Returns the value of attribute positions.
3 4 5 |
# File 'lib/mlb/player.rb', line 3 def positions @positions end |
#to ⇒ Object (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 |