Class: Zimbra::Appointment::RecurException

Inherits:
Object
  • Object
show all
Defined in:
lib/zimbra/appointment/recur_exception.rb

Constant Summary collapse

ATTRS =
[
  :recurrence_id,
  :timezone,
  :range_type
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ RecurException

Returns a new instance of RecurException.



33
34
35
# File 'lib/zimbra/appointment/recur_exception.rb', line 33

def initialize(args = {})
  self.attributes = args
end

Class Method Details

.new_from_zimbra_attributes(zimbra_attributes) ⇒ Object



5
6
7
8
# File 'lib/zimbra/appointment/recur_exception.rb', line 5

def new_from_zimbra_attributes(zimbra_attributes)
  return nil unless zimbra_attributes
  new(parse_zimbra_attributes(zimbra_attributes))
end

.parse_zimbra_attributes(zimbra_attributes) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/zimbra/appointment/recur_exception.rb', line 10

def parse_zimbra_attributes(zimbra_attributes)
  zimbra_attributes = Zimbra::Hash.symbolize_keys(zimbra_attributes.dup, true)

  {
    :recurrence_id => zimbra_attributes[:d],
    :timezone => zimbra_attributes[:tz],
    :range_type => zimbra_attributes[:rangeType]
  }
end

Instance Method Details

#attributes=(args = {}) ⇒ Object

take attributes by the xml name or our more descriptive name



38
39
40
41
42
# File 'lib/zimbra/appointment/recur_exception.rb', line 38

def attributes=(args = {})
  ATTRS.each do |attr_name|
    self.send(:"#{attr_name}=", (args[attr_name] || args[attr_name.to_s]))
  end
end

#create_xml(document) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/zimbra/appointment/recur_exception.rb', line 58

def create_xml(document)
  document.add "exceptId" do |except_element|
    except_element.set_attr "d", recurrence_id
    except_element.set_attr "tz", timezone
    except_element.set_attr "rangeType", range_type_to_zimbra if range_type
  end
end

#range_type=(val) ⇒ Object



29
30
31
# File 'lib/zimbra/appointment/recur_exception.rb', line 29

def range_type=(val)
  @range_type = parse_range_type(val)
end

#range_type_to_zimbraObject



54
55
56
# File 'lib/zimbra/appointment/recur_exception.rb', line 54

def range_type_to_zimbra
  possible_range_type_values.find { |k, v| v == range_type }.first rescue range_type
end

#to_hash(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/zimbra/appointment/recur_exception.rb', line 44

def to_hash(options = {})
  hash = ATTRS.inject({}) do |attr_hash, attr_name|
    attr_hash[attr_name] = self.send(:"#{attr_name}")
    attr_hash
  end
  hash.reject! { |key, value| options[:except].include?(key.to_sym) || options[:except].include?(key.to_s) } if options[:except]
  hash.reject! { |key, value| !options[:only].include?(key.to_sym) && !options[:only].include?(key.to_s) } if options[:only]
  hash
end