Class: DoubleEntry::Reporting::TimeRangeArray
- Inherits:
-
Object
- Object
- DoubleEntry::Reporting::TimeRangeArray
- Defined in:
- lib/double_entry/reporting/time_range_array.rb
Constant Summary collapse
- FACTORIES =
{ '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
Returns the value of attribute require_start.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #finish_range(finish = nil) ⇒ Object
-
#initialize(options = {}) ⇒ TimeRangeArray
constructor
A new instance of TimeRangeArray.
- #make(start = nil, finish = nil) ⇒ Object
- #start_range(start = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TimeRangeArray
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?
Returns the value of attribute require_start.
5 6 7 |
# File 'lib/double_entry/reporting/time_range_array.rb', line 5 def require_start @require_start end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
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
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
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
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
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 |