Class: DoubleEntry::Reporting::TimeRange
- Inherits:
-
Object
- Object
- DoubleEntry::Reporting::TimeRange
- Defined in:
- lib/double_entry/reporting/time_range.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#range_type ⇒ Object
readonly
Returns the value of attribute range_type.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#week ⇒ Object
readonly
Returns the value of attribute week.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #human_readable_name ⇒ Object
- #include?(time) ⇒ Boolean
-
#initialize(options) ⇒ TimeRange
constructor
A new instance of TimeRange.
- #key ⇒ Object
Constructor Details
#initialize(options) ⇒ TimeRange
Returns a new instance of TimeRange.
44 45 46 47 48 |
# File 'lib/double_entry/reporting/time_range.rb', line 44 def initialize() @year = [:year] @range_type = [:range_type] || :normal @month = @week = @day = @hour = nil end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def day @day end |
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
5 6 7 |
# File 'lib/double_entry/reporting/time_range.rb', line 5 def finish @finish end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def hour @hour end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def month @month end |
#range_type ⇒ Object (readonly)
Returns the value of attribute range_type.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def range_type @range_type end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
5 6 7 |
# File 'lib/double_entry/reporting/time_range.rb', line 5 def start @start end |
#week ⇒ Object (readonly)
Returns the value of attribute week.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def week @week end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
6 7 8 |
# File 'lib/double_entry/reporting/time_range.rb', line 6 def year @year end |
Class Method Details
.make(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/double_entry/reporting/time_range.rb', line 8 def self.make( = {}) @options = case when [:year] && [:week] && [:day] && [:hour] HourRange.new() when [:year] && [:week] && [:day] DayRange.new() when [:year] && [:week] WeekRange.new() when [:year] && [:month] MonthRange.new() when [:year] YearRange.new() else fail "Invalid range information #{}" end end |
.range_from_time_for_period(start_time, period_name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/double_entry/reporting/time_range.rb', line 26 def self.range_from_time_for_period(start_time, period_name) case period_name when 'month' YearRange.from_time(start_time) when 'week' YearRange.from_time(start_time) when 'day' MonthRange.from_time(start_time) when 'hour' DayRange.from_time(start_time) end end |
Instance Method Details
#human_readable_name ⇒ Object
54 55 56 |
# File 'lib/double_entry/reporting/time_range.rb', line 54 def human_readable_name self.class.name.gsub('DoubleEntry::Reporting::', '').gsub('Range', '') end |
#include?(time) ⇒ Boolean
39 40 41 42 |
# File 'lib/double_entry/reporting/time_range.rb', line 39 def include?(time) time >= @start && time <= @finish end |
#key ⇒ Object
50 51 52 |
# File 'lib/double_entry/reporting/time_range.rb', line 50 def key "#{@year}:#{@month}:#{@week}:#{@day}:#{@hour}" end |