Module: Reporter::Support::TimeRange

Defined in:
lib/reporter/support/time_range.rb

Instance Method Summary collapse

Instance Method Details

#human_nameObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reporter/support/time_range.rb', line 10

def human_name
  return inspect unless time_range?
  b = test_begin_ends(self.begin)
  e = test_begin_ends(self.end)

  if self.begin.year == self.end.year
    if b[:by] and e[:ey]
      return self.begin.strftime("%Y")
    elsif b[:bq] and e[:eq]
      bq = get_quarter(self.begin)
      eq = get_quarter(self.end)
      if bq == eq
        return I18n.t("time_range.quarter", :year => self.begin.year, :quarter => bq, :default => "q%{quarter} %{year}")
      else
        return I18n.t("time_range.multi_quarter", :year => self.begin.year,
                      :begin_quarter => bq, :end_quarter => eq, :default => "q%{begin_quarter} .. q%{end_quarter} %{year}")
      end
    elsif b[:bm] and e[:em]
      if self.begin.month == self.end.month
        return self.begin.strftime("%b '%y")
      else
        return "#{self.begin.strftime("%b")} .. #{self.end.strftime("%b '%y")}"
      end
    end
  else # multi year
    if b[:by] and e[:ey]
      return "#{self.begin.strftime("'%y")} .. #{self.end.strftime("'%y")}"
    else
      return inspect
    end
  end
end

#time_range?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
# File 'lib/reporter/support/time_range.rb', line 3

def time_range?
  valid_types = [Date, DateTime, Time, ActiveSupport::TimeWithZone]
  return false unless valid_types.include?(self.begin.class)
  return false unless valid_types.include?(self.end.class)
  true
end