Class: DoubleEntry::Reporting::TimeRange Private

Inherits:
Object
  • Object
show all
Defined in:
lib/double_entry/reporting/time_range.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.

Direct Known Subclasses

DayRange, HourRange, MonthRange, WeekRange, YearRange

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TimeRange

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 TimeRange.



44
45
46
47
48
# File 'lib/double_entry/reporting/time_range.rb', line 44

def initialize(options)
  @year = options[:year]
  @range_type = options[:range_type] || :normal
  @month = @week = @day = @hour = nil
end

Instance Attribute Details

#dayObject (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.



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

def day
  @day
end

#finishObject (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.rb', line 5

def finish
  @finish
end

#hourObject (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.



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

def hour
  @hour
end

#monthObject (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.



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

def month
  @month
end

#range_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.



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

def range_type
  @range_type
end

#startObject (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.rb', line 5

def start
  @start
end

#weekObject (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.



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

def week
  @week
end

#yearObject (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.



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

def year
  @year
end

Class Method Details

.make(options = {}) ⇒ 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.



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 = {})
  @options = options
  case
  when options[:year] && options[:week] && options[:day] && options[:hour]
    HourRange.new(options)
  when options[:year] && options[:week] && options[:day]
    DayRange.new(options)
  when options[:year] && options[:week]
    WeekRange.new(options)
  when options[:year] && options[:month]
    MonthRange.new(options)
  when options[:year]
    YearRange.new(options)
  else
    fail "Invalid range information #{options}"
  end
end

.range_from_time_for_period(start_time, period_name) ⇒ 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.



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_nameObject

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.



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

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:

  • (Boolean)


39
40
41
42
# File 'lib/double_entry/reporting/time_range.rb', line 39

def include?(time)
  time >= @start &&
    time <= @finish
end

#keyObject

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.



50
51
52
# File 'lib/double_entry/reporting/time_range.rb', line 50

def key
  "#{@year}:#{@month}:#{@week}:#{@day}:#{@hour}"
end