Class: Zimbra::Appointment::Alarm
- Inherits:
-
Object
- Object
- Zimbra::Appointment::Alarm
- Defined in:
- lib/zimbra/appointment/alarm.rb
Constant Summary collapse
- ATTRS =
[:appointment_invite, :duration_negative, :weeks, :days, :hours, :minutes, :seconds, :when, :repeat_count]
Class Method Summary collapse
- .new_from_zimbra_attributes(zimbra_attributes) ⇒ Object
-
.parse_zimbra_attributes(zimbra_attributes) ⇒ Object
<alarm action=“DISPLAY”> <trigger> <rel neg=“1” m=“5” related=“START”/> </trigger> <desc/> </alarm>.
Instance Method Summary collapse
-
#attributes=(args = {}) ⇒ Object
take attributes by the xml name or our more descriptive name.
- #create_xml(document) ⇒ Object
- #date_time_of_alarm ⇒ Object
-
#initialize(args = {}) ⇒ Alarm
constructor
A new instance of Alarm.
- #to_hash(options = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Alarm
Returns a new instance of Alarm.
39 40 41 42 43 |
# File 'lib/zimbra/appointment/alarm.rb', line 39 def initialize(args = {}) @duration_negative = true @when = :start self.attributes = args end |
Class Method Details
.new_from_zimbra_attributes(zimbra_attributes) ⇒ Object
5 6 7 |
# File 'lib/zimbra/appointment/alarm.rb', line 5 def new_from_zimbra_attributes(zimbra_attributes) new(parse_zimbra_attributes(zimbra_attributes)) end |
.parse_zimbra_attributes(zimbra_attributes) ⇒ Object
<alarm action=“DISPLAY”>
<trigger>
<rel neg="1" m="5" related="START"/>
</trigger>
<desc/>
</alarm>
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zimbra/appointment/alarm.rb', line 15 def parse_zimbra_attributes(zimbra_attributes) attrs = { appointment_invite: zimbra_attributes[:appointment_invite] } zimbra_attributes = Zimbra::Hash.symbolize_keys(zimbra_attributes.dup, true) zimbra_attributes = zimbra_attributes[:trigger][:rel][:attributes] duration_negative = (zimbra_attributes[:neg] && zimbra_attributes[:neg] == 1) ? true : false attrs.merge({ duration_negative: duration_negative, weeks: zimbra_attributes[:w], days: zimbra_attributes[:d], hours: zimbra_attributes[:h], minutes: zimbra_attributes[:m], seconds: zimbra_attributes[:s], when: zimbra_attributes[:related] == "START" ? :start : :end, repeat_count: zimbra_attributes[:count], }) end |
Instance Method Details
#attributes=(args = {}) ⇒ Object
take attributes by the xml name or our more descriptive name
46 47 48 49 50 51 52 53 54 |
# File 'lib/zimbra/appointment/alarm.rb', line 46 def attributes=(args = {}) ATTRS.each do |attr_name| if args.has_key?(attr_name) self.send(:"#{attr_name}=", args[attr_name]) elsif args.has_key?(attr_name.to_s) self.send(:"#{attr_name}=", args[attr_name.to_s]) end end end |
#create_xml(document) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/zimbra/appointment/alarm.rb', line 66 def create_xml(document) document.add "trigger" do |trigger_element| trigger_element.add "rel" do |rel_element| rel_element.set_attr "neg", duration_negative ? 1 : 0 rel_element.set_attr "w", weeks if weeks && weeks > 0 rel_element.set_attr "d", days if days && days > 0 rel_element.set_attr "h", hours if hours && hours > 0 rel_element.set_attr "m", minutes if minutes && minutes > 0 rel_element.set_attr "s", seconds if seconds && seconds > 0 rel_element.set_attr "related", self.when.to_s.upcase rel_element.set_attr "count", repeat_count if repeat_count && repeat_count > 0 end end end |
#date_time_of_alarm ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/zimbra/appointment/alarm.rb', line 81 def date_time_of_alarm return nil if appointment_invite.nil? date_to_calc_from = if self.when == :start appointment_invite.start_date_time else appointment_invite.end_date_time end total_seconds = seconds || 0 total_seconds += minutes * 60 if minutes total_seconds += hours * 3600 if hours total_seconds += days * 86400 if days total_seconds += weeks * 86400 * 7 if weeks total_seconds *= -1 if duration_negative date_to_calc_from + total_seconds end |
#to_hash(options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/zimbra/appointment/alarm.rb', line 56 def to_hash( = {}) hash = ATTRS.inject({}) do |attr_hash, attr_name| attr_hash[attr_name] = self.send(:"#{attr_name}") attr_hash end hash.reject! { |key, value| [:except].include?(key.to_sym) || [:except].include?(key.to_s) } if [:except] hash.reject! { |key, value| ![:only].include?(key.to_sym) && ![:only].include?(key.to_s) } if [:only] hash end |