Class: TimeFrame::Splitter

Inherits:
Object
  • Object
show all
Defined in:
lib/time_frame/time_frame_splitter.rb

Overview

Provides a method to split a time frame by a given interval. It returns an array which contains the intervals as TimeFrame instances.

Instance Method Summary collapse

Constructor Details

#initialize(time_frame) ⇒ Splitter

Returns a new instance of Splitter.



6
7
8
# File 'lib/time_frame/time_frame_splitter.rb', line 6

def initialize(time_frame)
  @time_frame = time_frame
end

Instance Method Details

#split_by(interval) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/time_frame/time_frame_splitter.rb', line 10

def split_by(interval)
  time = @time_frame.min
  max = @time_frame.max
  time_frames = []
  until time >= max
    time_old = time
    time += interval
    time_frames << TimeFrame.new(min: time_old, max: [time, max].min)
  end
  time_frames
end