Class: DoubleEntry::Reporting::TimeRangeArray Private

Inherits:
Object
  • Object
show all
Defined in:
lib/double_entry/reporting/time_range_array.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Constant Summary collapse

FACTORIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

{
  'hour'  => new(:type => HourRange,  :require_start => true),
  'day'   => new(:type => DayRange,   :require_start => true),
  'week'  => new(:type => WeekRange,  :require_start => true),
  'month' => new(:type => MonthRange, :require_start => false),
  'year'  => new(:type => YearRange,  :require_start => false),
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TimeRangeArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TimeRangeArray.

API:

  • private



9
10
11
12
# File 'lib/double_entry/reporting/time_range_array.rb', line 9

def initialize(options = {})
  @type = options[:type]
  @require_start = options[:require_start]
end

Instance Attribute Details

#require_startObject (readonly) Also known as: require_start?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'lib/double_entry/reporting/time_range_array.rb', line 6

def require_start
  @require_start
end

#typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



6
7
8
# File 'lib/double_entry/reporting/time_range_array.rb', line 6

def type
  @type
end

Class Method Details

.make(range_type, start = nil, finish = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

API:

  • private



43
44
45
46
47
# File 'lib/double_entry/reporting/time_range_array.rb', line 43

def self.make(range_type, start = nil, finish = nil)
  factory = FACTORIES[range_type]
  raise ArgumentError.new("Invalid range type '#{range_type}'") unless factory
  factory.make(start, finish)
end

Instance Method Details

#finish_range(finish = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



31
32
33
# File 'lib/double_entry/reporting/time_range_array.rb', line 31

def finish_range(finish = nil)
  finish ? type.from_time(Time.parse(finish)) : type.current
end

#make(start = nil, finish = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



14
15
16
17
18
19
20
21
22
23
# File 'lib/double_entry/reporting/time_range_array.rb', line 14

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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



25
26
27
28
29
# File 'lib/double_entry/reporting/time_range_array.rb', line 25

def start_range(start = nil)
  raise "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