Class: SimulatorTimeline::Minute

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

Instance Method Summary collapse

Constructor Details

#initialize(timeline, period_time, minute) {|_self| ... } ⇒ Minute

Returns a new instance of Minute.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(timeline, period_time, minute)
  @timeline, @period_time, @minute = timeline, period_time, minute
  yield(self) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
# File 'app/models/simulator_timeline/minute.rb', line 18

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

Instance Method Details

#event_handlerObject



8
9
10
# File 'app/models/simulator_timeline/minute.rb', line 8

def event_handler
  @event_handler ||= EventHandler.new(@timeline, @period_time, @minute)
end

#reached_time?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/models/simulator_timeline/minute.rb', line 12

def reached_time?
  @timeline.current_period_time > @period_time || (
    @timeline.current_period_time == @period_time && @timeline.current_minute >= @minute
  )
end