Class: DoubleEntry::TimeRange
- Inherits:
-
Object
- Object
- DoubleEntry::TimeRange
- Defined in:
- lib/double_entry/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.
42 43 44 45 |
# File 'lib/double_entry/time_range.rb', line 42 def initialize() @year = [:year] @range_type = [:range_type] || :normal end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def day @day end |
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
4 5 6 |
# File 'lib/double_entry/time_range.rb', line 4 def finish @finish end |
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def hour @hour end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def month @month end |
#range_type ⇒ Object (readonly)
Returns the value of attribute range_type.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def range_type @range_type end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
4 5 6 |
# File 'lib/double_entry/time_range.rb', line 4 def start @start end |
#week ⇒ Object (readonly)
Returns the value of attribute week.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def week @week end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/double_entry/time_range.rb', line 5 def year @year end |
Class Method Details
.make(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/double_entry/time_range.rb', line 7 def self.make( = {}) @options = case when ([:year] and [:week] and [:day] and [:hour]) HourRange.new() when ([:year] and [:week] and [:day]) DayRange.new() when ([:year] and [:week]) WeekRange.new() when ([:year] and [:month]) MonthRange.new() when [:year] YearRange.new() else raise "Invalid range information #{}" end end |
.range_from_time_for_period(start_time, period_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/double_entry/time_range.rb', line 25 def self.range_from_time_for_period(start_time, period_name) case period_name when 'month' DoubleEntry::YearRange.from_time(start_time) when 'week' DoubleEntry::YearRange.from_time(start_time) when 'day' DoubleEntry::MonthRange.from_time(start_time) when 'hour' DoubleEntry::DayRange.from_time(start_time) end end |
Instance Method Details
#human_readable_name ⇒ Object
51 52 53 |
# File 'lib/double_entry/time_range.rb', line 51 def human_readable_name self.class.name.gsub('DoubleEntry::', '').gsub('Range', '') end |
#include?(time) ⇒ Boolean
38 39 40 |
# File 'lib/double_entry/time_range.rb', line 38 def include?(time) (time >= @start) and (time <= @finish) end |
#key ⇒ Object
47 48 49 |
# File 'lib/double_entry/time_range.rb', line 47 def key "#{@year}:#{@month}:#{@week}:#{@day}:#{@hour}" end |