Class: DoubleEntry::Reporting::TimeRangeArray Private
- Inherits:
-
Object
- Object
- DoubleEntry::Reporting::TimeRangeArray
- Defined in:
- lib/double_entry/reporting/time_range_array.rb
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.
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.
{ '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
- #require_start ⇒ Object (also: #require_start?) readonly private
- #type ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #finish_range(finish = nil) ⇒ Object private
-
#initialize(options = {}) ⇒ TimeRangeArray
constructor
private
A new instance of TimeRangeArray.
- #make(start = nil, finish = nil) ⇒ Object private
- #start_range(start = nil) ⇒ Object private
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.
8 9 10 11 |
# File 'lib/double_entry/reporting/time_range_array.rb', line 8 def initialize( = {}) @type = [:type] @require_start = [:require_start] end |
Instance Attribute Details
#require_start ⇒ Object (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.
5 6 7 |
# File 'lib/double_entry/reporting/time_range_array.rb', line 5 def require_start @require_start end |
#type ⇒ Object (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.
5 6 7 |
# File 'lib/double_entry/reporting/time_range_array.rb', line 5 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.
42 43 44 45 46 |
# 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 |
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.
30 31 32 |
# 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) ⇒ 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.
13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ 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.
24 25 26 27 28 |
# 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 |