Class: Zimbra::DateHelpers::Frequency
- Inherits:
-
Object
- Object
- Zimbra::DateHelpers::Frequency
- 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
-
#abbreviations ⇒ Object
Returns the value of attribute abbreviations.
-
#name ⇒ Object
Returns the value of attribute name.
-
#zimbra_name ⇒ Object
Returns the value of attribute zimbra_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Frequency
constructor
A new instance of Frequency.
- #match?(name_or_abbreviation) ⇒ Boolean
- #to_sym ⇒ Object
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
#abbreviations ⇒ Object
Returns the value of attribute abbreviations.
26 27 28 |
# File 'lib/zimbra/extra/date_helpers.rb', line 26 def abbreviations @abbreviations end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/zimbra/extra/date_helpers.rb', line 26 def name @name end |
#zimbra_name ⇒ Object
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
.all ⇒ Object
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
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_sym ⇒ Object
39 40 41 |
# File 'lib/zimbra/extra/date_helpers.rb', line 39 def to_sym name.downcase.to_sym end |