Class: DateLabelHelper::GenericDateView

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
app/helpers/date_label_helper.rb

Direct Known Subclasses

DueDateView, ShowFromDateView

Constant Summary collapse

COLORS =
{
  :overdue_by_more_than_one => :red,
  :overdue_by_one           => :red,
  :today                    => :amber,
  :tomorrow                 => :amber,
  :this_week                => :orange,
  :more_than_a_week         => :green
}

Instance Method Summary collapse

Constructor Details

#initialize(date, prefs) ⇒ GenericDateView



16
17
18
19
20
21
# File 'app/helpers/date_label_helper.rb', line 16

def initialize(date, prefs)
  @date = date
  @days = date.nil? ? nil : days_from_today(date)
  @days_sym = days_to_sym(@days)
  @prefs = prefs
end

Instance Method Details

#date_html_wrapperObject



52
53
54
55
56
57
58
59
60
# File 'app/helpers/date_label_helper.rb', line 52

def date_html_wrapper
  return "" if @date.nil?

  return (:a, {:title => @prefs.format_date(@date)}) {
          (:span, {:class => get_color}) {
            yield
          }
        }
end

#date_mobile_html_wrapperObject



62
63
64
65
66
67
68
# File 'app/helpers/date_label_helper.rb', line 62

def date_mobile_html_wrapper
  return "" if @date.nil?

  return (:span, {:class => get_color}) {
    yield
  }
end

#days_from_today(date) ⇒ Object



27
28
29
# File 'app/helpers/date_label_helper.rb', line 27

def days_from_today(date)
  (date.in_time_zone.to_date - Date.current).to_i
end

#days_to_sym(days) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/date_label_helper.rb', line 31

def days_to_sym(days)
  case days
  when nil
    return nil
  when 0
    return :today
  when 1
    return :tomorrow
  when 2..7
    return :this_week
  else
    if days == -1
      return :overdue_by_one
    elsif days < -1
      return :overdue_by_more_than_one
    else
      return :more_than_a_week
    end
  end
end

#get_colorObject



23
24
25
# File 'app/helpers/date_label_helper.rb', line 23

def get_color
  COLORS[@days_sym]
end