Class: Zimbra::DateHelpers::WeekDay

Inherits:
Object
  • Object
show all
Defined in:
lib/zimbra/extra/date_helpers.rb

Constant Summary collapse

WEEK_DAYS =
[
  {
    id: 1, name: :Sunday, zimbra_name: 'SU',
    abbreviations: ['su', 'sun']
  },
  {
    id: 2, name: :Monday, zimbra_name: 'MO', 
    abbreviations: ['mo', 'mon']
  },
  {
    id: 3, name: :Tuesday, zimbra_name: 'TU', 
    abbreviations: ['tu', 'tue']
  },
  {
    id: 4, name: :Wednesday, zimbra_name: 'WE', 
    abbreviations: ['we', 'wed']
  },
  {
    id: 5, name: :Thursday, zimbra_name: 'TH', 
    abbreviations: ['th', 'thu', 'thur', 'thurs']
  },
  {
    id: 6, name: :Friday, zimbra_name: 'FR', 
    abbreviations: ['fr', 'fri']
  },
  {
    id: 7, name: :Saturday, zimbra_name: 'SA', 
    abbreviations: ['sa', 'sat']
  }
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ WeekDay

Returns a new instance of WeekDay.



90
91
92
93
94
95
# File 'lib/zimbra/extra/date_helpers.rb', line 90

def initialize(args = {})
  @id = args[:id]
  @name = args[:name]
  @zimbra_name = args[:zimbra_name]
  @abbreviations = args[:abbreviations]
end

Instance Attribute Details

#abbreviationsObject

Returns the value of attribute abbreviations.



88
89
90
# File 'lib/zimbra/extra/date_helpers.rb', line 88

def abbreviations
  @abbreviations
end

#idObject

Returns the value of attribute id.



88
89
90
# File 'lib/zimbra/extra/date_helpers.rb', line 88

def id
  @id
end

#nameObject

Returns the value of attribute name.



88
89
90
# File 'lib/zimbra/extra/date_helpers.rb', line 88

def name
  @name
end

#zimbra_nameObject

Returns the value of attribute zimbra_name.



88
89
90
# File 'lib/zimbra/extra/date_helpers.rb', line 88

def zimbra_name
  @zimbra_name
end

Class Method Details

.allObject



77
78
79
80
81
# File 'lib/zimbra/extra/date_helpers.rb', line 77

def all
  @all ||= WEEK_DAYS.inject([]) do |week_days, data|
    week_days << new(data)
  end
end

.find(id_name_or_abbreviation) ⇒ Object



83
84
85
# File 'lib/zimbra/extra/date_helpers.rb', line 83

def find(id_name_or_abbreviation)
  all.find { |week_day| week_day.match?(id_name_or_abbreviation) }
end

Instance Method Details

#match?(id_name_or_abbreviation) ⇒ Boolean

Returns:



97
98
99
100
101
102
103
104
# File 'lib/zimbra/extra/date_helpers.rb', line 97

def match?(id_name_or_abbreviation)
  if id_name_or_abbreviation.is_a?(Fixnum)
    id_name_or_abbreviation == id
  else
    downcased_matcher = id_name_or_abbreviation.to_s.downcase
    ([name.to_s, zimbra_name.to_s] + abbreviations).map(&:downcase).include?(downcased_matcher)
  end
end

#to_symObject



106
107
108
# File 'lib/zimbra/extra/date_helpers.rb', line 106

def to_sym
  name.downcase.to_sym
end