Class: Zimbra::DateHelpers::Frequency

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

Constant Summary collapse

FREQUENCIES =
[
  { name: :secondly, zimbra_name: 'SEC', abbreviations: [] },
  { name: :minutely, zimbra_name: 'MIN', abbreviations: [] },
  { name: :hourly,   zimbra_name: 'HOU', abbreviations: [] },
  { name: :daily,    zimbra_name: 'DAI', abbreviations: [] },
  { name: :weekly,   zimbra_name: 'WEE', abbreviations: [] },
  { name: :monthly,  zimbra_name: 'MON', abbreviations: [] },
  { name: :yearly,   zimbra_name: 'YEA', abbreviations: [] }
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Frequency

Returns a new instance of Frequency.



28
29
30
31
32
# File 'lib/zimbra/extra/date_helpers.rb', line 28

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

Instance Attribute Details

#abbreviationsObject

Returns the value of attribute abbreviations.



26
27
28
# File 'lib/zimbra/extra/date_helpers.rb', line 26

def abbreviations
  @abbreviations
end

#nameObject

Returns the value of attribute name.



26
27
28
# File 'lib/zimbra/extra/date_helpers.rb', line 26

def name
  @name
end

#zimbra_nameObject

Returns the value of attribute zimbra_name.



26
27
28
# File 'lib/zimbra/extra/date_helpers.rb', line 26

def zimbra_name
  @zimbra_name
end

Class Method Details

.allObject



15
16
17
18
19
# File 'lib/zimbra/extra/date_helpers.rb', line 15

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

.find(name_or_abbreviation) ⇒ Object



21
22
23
# File 'lib/zimbra/extra/date_helpers.rb', line 21

def find(name_or_abbreviation)
  all.find { |frequency| frequency.match?(name_or_abbreviation) }
end

Instance Method Details

#match?(name_or_abbreviation) ⇒ Boolean

Returns:



34
35
36
37
# File 'lib/zimbra/extra/date_helpers.rb', line 34

def match?(name_or_abbreviation)
  downcased_matcher = name_or_abbreviation.to_s.downcase
  ([name.to_s, zimbra_name.to_s] + abbreviations).map(&:downcase).include?(downcased_matcher)
end

#to_symObject



39
40
41
# File 'lib/zimbra/extra/date_helpers.rb', line 39

def to_sym
  name.downcase.to_sym
end