class TimeFrame::Splitter
Provides a method to split a time frame by a given interval. It returns an array which contains the intervals as TimeFrame
instances.
Public Class Methods
new(time_frame)
click to toggle source
# File lib/time_frame/time_frame_splitter.rb, line 6 def initialize(time_frame) @time_frame = time_frame end
Public Instance Methods
split_by(interval)
click to toggle source
# 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