Class: SimulatorTimeline::PlayerEvent

Inherits:
Event
  • Object
show all
Defined in:
app/models/simulator_timeline/player_event.rb

Instance Attribute Summary collapse

Attributes inherited from Event

#event_handler, #minute, #period_time

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

#<=>, fuck_collection

Constructor Details

#initialize(event_handler, timeline, period_time, minute, options = {}) ⇒ PlayerEvent

Returns a new instance of PlayerEvent.



7
8
9
10
11
12
13
# File 'app/models/simulator_timeline/player_event.rb', line 7

def initialize(event_handler, timeline, period_time, minute, options = {})
  @player, @reference, @status, substituted_index = options.values_at :player, :reference, :status, :substituted
  @playing  = true
  @status ||= "Titular"
  set_substituted(substituted_index) if substituted_index
  super(event_handler, timeline, period_time, minute, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'app/models/simulator_timeline/player_event.rb', line 35

def method_missing(method_name, *args, &block)
  if @player.respond_to?(method_name)
    @player.public_send(method_name, *args, &block)
  else
    super(method_name, *args, &block)
  end
end

Instance Attribute Details

#playerObject (readonly)

Returns the value of attribute player.



5
6
7
# File 'app/models/simulator_timeline/player_event.rb', line 5

def player
  @player
end

#playingObject

Returns the value of attribute playing.



3
4
5
# File 'app/models/simulator_timeline/player_event.rb', line 3

def playing
  @playing
end

#referenceObject (readonly)

Returns the value of attribute reference.



5
6
7
# File 'app/models/simulator_timeline/player_event.rb', line 5

def reference
  @reference
end

#substitutedObject (readonly)

Returns the value of attribute substituted.



5
6
7
# File 'app/models/simulator_timeline/player_event.rb', line 5

def substituted
  @substituted
end

Class Method Details

.remove(timeline, reference) ⇒ Object



26
27
28
29
# File 'app/models/simulator_timeline/player_event.rb', line 26

def self.remove(timeline, reference)
  timeline.current_home_players.delete_all{ |event| event.reference == reference }
  timeline.current_visitor_players.delete_all{ |event| event.reference == reference }
end

.to_foot_stats(array_of_players) ⇒ Object



31
32
33
# File 'app/models/simulator_timeline/player_event.rb', line 31

def self.to_foot_stats(array_of_players)
  fuck_collection 'Jogador', array_of_players.map(&:to_foot_stats)
end

Instance Method Details

#to_foot_statsObject



15
16
17
18
19
20
21
22
23
24
# File 'app/models/simulator_timeline/player_event.rb', line 15

def to_foot_stats
  {
    "@Jogador"    => @player.full_name,
    "@IdJogador"  => @player.source_id,
    "@Status"     => @status,
    "@Substituto" => (@substituted || ''),
    "@Periodo"    => (@substituted ? SimulatorMatch::STATUS_MAP[SimulatorMatch::STATUSES[@period_time]] : 'Nenhum'),
    "@Minuto"     => @minute.to_s
  }
end