Class: DoubleEntry::Reporting::TimeRange Private

Inherits:
Object
  • Object
show all
Defined in:
lib/double_entry/reporting/time_range.rb

Overview

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.

API:

  • private

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.

API:

  • private



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

def initialize(options)
  @year = options[:year]
  @range_type = options[:range_type] || :normal
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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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.

API:

  • private



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] and options[:week] and options[:day] and options[:hour])
      HourRange.new(options)
    when (options[:year] and options[:week] and options[:day])
      DayRange.new(options)
    when (options[:year] and options[:week])
      WeekRange.new(options)
    when (options[:year] and options[:month])
      MonthRange.new(options)
    when options[:year]
      YearRange.new(options)
    else
      raise "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.

API:

  • private



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.

API:

  • private



52
53
54
# File 'lib/double_entry/reporting/time_range.rb', line 52

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:

API:

  • private



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

def include?(time)
  (time >= @start) and (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.

API:

  • private



48
49
50
# File 'lib/double_entry/reporting/time_range.rb', line 48

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