class DoubleEntry::Reporting::TimeRangeArray

Constants

FACTORIES

Attributes

require_start[R]
require_start?[R]
type[R]

Public Class Methods

make(range_type, start = nil, finish = nil) click to toggle source
# File lib/double_entry/reporting/time_range_array.rb, line 42
def self.make(range_type, start = nil, finish = nil)
  factory = FACTORIES[range_type]
  fail ArgumentError, "Invalid range type '#{range_type}'" unless factory
  factory.make(start, finish)
end
new(options = {}) click to toggle source
# File lib/double_entry/reporting/time_range_array.rb, line 8
def initialize(options = {})
  @type = options[:type]
  @require_start = options[:require_start]
end

Public Instance Methods

finish_range(finish = nil) click to toggle source
# File lib/double_entry/reporting/time_range_array.rb, line 30
def finish_range(finish = nil)
  finish ? type.from_time(Time.parse(finish)) : type.current
end
make(start = nil, finish = nil) click to toggle source
# File lib/double_entry/reporting/time_range_array.rb, line 13
def make(start = nil, finish = nil)
  start = start_range(start)
  finish = finish_range(finish)
  [start].tap do |array|
    while start != finish
      start = start.next
      array << start
    end
  end
end
start_range(start = nil) click to toggle source
# File lib/double_entry/reporting/time_range_array.rb, line 24
def start_range(start = nil)
  fail 'Must specify start of range' if start.blank? && require_start?
  start_time = start ? Time.parse(start) : Reporting.configuration.start_of_business
  type.from_time(start_time)
end