Class: DoubleEntry::Reporting::DayRange

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

Instance Attribute Summary collapse

Attributes inherited from TimeRange

#finish, #hour, #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) ⇒ DayRange

Returns a new instance of DayRange.



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

def initialize(options)
  super options

  @week = options[:week]
  @day = options[:day]
  week_range = WeekRange.new(options)

  @start = week_range.start + (options[:day] - 1).days
  @finish = @start.end_of_day
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



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

def day
  @day
end

#weekObject (readonly)

Returns the value of attribute week.



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

def week
  @week
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Class Method Details

.from_time(time) ⇒ Object



18
19
20
21
# File 'lib/double_entry/reporting/day_range.rb', line 18

def self.from_time(time)
  week_range = WeekRange.from_time(time)
  DayRange.new(:year => week_range.year, :week => week_range.week, :day => time.wday == 0 ? 7 : time.wday)
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
# File 'lib/double_entry/reporting/day_range.rb', line 31

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

#nextObject



27
28
29
# File 'lib/double_entry/reporting/day_range.rb', line 27

def next
  DayRange.from_time(@start + 1.day)
end

#previousObject



23
24
25
# File 'lib/double_entry/reporting/day_range.rb', line 23

def previous
  DayRange.from_time(@start - 1.day)
end

#to_sObject



37
38
39
# File 'lib/double_entry/reporting/day_range.rb', line 37

def to_s
  start.strftime('%Y, %a %b %d')
end