Method: TimeWise::Base#slice

Defined in:
lib/time_wise/base.rb

#slice(start_idx, end_idx) ⇒ TimeWise::Base

Get a section of the time series

Parameters:

  • start_idx (Integer)

    Starting index

  • end_idx (Integer)

    Ending index

Returns:

  • (TimeWise::Base)

    A new time series with the specified data range



43
44
45
46
47
48
49
50
# File 'lib/time_wise/base.rb', line 43

def slice(start_idx, end_idx)
  end_idx = @data.size - 1 if end_idx >= @data.size

  new_data = @data[start_idx..end_idx]
  new_dates = @has_dates ? @dates[start_idx..end_idx] : nil

  TimeWise.create(new_data.to_a, new_dates)
end