Class: DoubleEntry::Reporting::HourRange

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

Instance Attribute Summary collapse

Attributes inherited from TimeRange

#finish, #month, #range_type, #start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TimeRange

#human_readable_name, #include?, #key, make, range_from_time_for_period

Constructor Details

#initialize(options) ⇒ HourRange

Returns a new instance of HourRange.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/double_entry/reporting/hour_range.rb', line 7

def initialize(options)
  super options

  @week = options[:week]
  @day = options[:day]
  @hour = options[:hour]

  day_range = DayRange.new(options)

  @start = day_range.start + options[:hour].hours
  @finish = @start.end_of_hour
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



5
6
7
# File 'lib/double_entry/reporting/hour_range.rb', line 5

def day
  @day
end

#hourObject (readonly)

Returns the value of attribute hour.



5
6
7
# File 'lib/double_entry/reporting/hour_range.rb', line 5

def hour
  @hour
end

#weekObject (readonly)

Returns the value of attribute week.



5
6
7
# File 'lib/double_entry/reporting/hour_range.rb', line 5

def week
  @week
end

#yearObject (readonly)

Returns the value of attribute year.



5
6
7
# File 'lib/double_entry/reporting/hour_range.rb', line 5

def year
  @year
end

Class Method Details

.from_time(time) ⇒ Object



20
21
22
23
# File 'lib/double_entry/reporting/hour_range.rb', line 20

def self.from_time(time)
  day = DayRange.from_time(time)
  HourRange.new :year => day.year, :week => day.week, :day => day.day, :hour => time.hour
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
# File 'lib/double_entry/reporting/hour_range.rb', line 33

def ==(other)
  week == other.week &&
    year == other.year &&
    day == other.day &&
    hour == other.hour
end

#nextObject



29
30
31
# File 'lib/double_entry/reporting/hour_range.rb', line 29

def next
  HourRange.from_time(@start + 1.hour)
end

#previousObject



25
26
27
# File 'lib/double_entry/reporting/hour_range.rb', line 25

def previous
  HourRange.from_time(@start - 1.hour)
end

#to_sObject



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

def to_s
  "#{start.hour}:00:00 - #{start.hour}:59:59"
end