Class: InOrOut::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/in_or_out/models/match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(home_team, round, away_team = nil) ⇒ Match

Returns a new instance of Match.



10
11
12
13
14
# File 'lib/in_or_out/models/match.rb', line 10

def initialize(home_team, round, away_team = nil)
  @home_team, @away_team, @round = home_team, away_team, round
  @players = InOrOut::PlayerExtractor.new(download_match_data).extract
  @players.empty? ? @status = 'pending' : @status = 'ready'
end

Instance Attribute Details

#playersObject (readonly)

Returns the value of attribute players.



8
9
10
# File 'lib/in_or_out/models/match.rb', line 8

def players
  @players
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/in_or_out/models/match.rb', line 8

def status
  @status
end

Class Method Details

.find(**options) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/in_or_out/models/match.rb', line 20

def self.find(**options)
  match = AFL::Schedule.new.next_match(options[:team])
  if match
    self.new(match[:home_team], match[:round], match[:away_team])
  else
    match
  end
end

Instance Method Details

#find_player(player_name, team_name) ⇒ Object



16
17
18
# File 'lib/in_or_out/models/match.rb', line 16

def find_player(player_name, team_name)
  @players.detect { |player| player.name == player_name && player.team == team_name }
end