Class: Exchanger::Item

Inherits:
Element show all
Defined in:
lib/exchanger/elements/item.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#tag_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#==, #assign_attributes_from_xml, create_element_accessors, element, #errors, #initialize, #inspect, key, new_from_xml, #to_xml, #to_xml_change, #to_xml_updates

Methods included from Persistence

#destroy, #new_record?, #persisted?, #reload, #save

Methods included from Dirty

#attribute_change, #attribute_changed?, #attribute_was, #changed, #changed?, #changes, included, #move_changes, #previous_changes, #reset_attribute!, #reset_modifications, #setup_modifications

Methods included from Attributes

#attributes, #attributes=, #change_key, #id, #identifier, #method_missing, #read_attribute, #respond_to?, #write_attribute

Constructor Details

This class inherits a constructor from Exchanger::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Exchanger::Attributes

Instance Attribute Details

#parent_folderObject



65
66
67
68
69
# File 'lib/exchanger/elements/item.rb', line 65

def parent_folder
  @parent_folder ||= if parent_folder_id
    Folder.find(parent_folder_id.id)
  end
end

Class Method Details

.find(id) ⇒ Object



40
41
42
# File 'lib/exchanger/elements/item.rb', line 40

def self.find(id)
  find_all([id]).first
end

.find_all(ids) ⇒ Object



44
45
46
47
# File 'lib/exchanger/elements/item.rb', line 44

def self.find_all(ids)
  response = GetItem.run(:item_ids => ids)
  response.items
end

.find_all_by_folder_id(folder_id, email_address = nil) ⇒ Object



49
50
51
52
# File 'lib/exchanger/elements/item.rb', line 49

def self.find_all_by_folder_id(folder_id, email_address = nil)
  response = FindItem.run(:folder_id => folder_id, :email_address => email_address)
  response.items
end

.find_calendar_view_set_by_folder_id(folder_id, calendar_view) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/exchanger/elements/item.rb', line 54

def self.find_calendar_view_set_by_folder_id(folder_id, calendar_view)
  response = FindItem.run(
    folder_id:     folder_id,
    calendar_view: calendar_view,
  )

  response.items
end

Instance Method Details

#categories_with_colorObject

TODO The 0.2.1 implementation is depended on the language of the integration. This code only works if the user have selected English as their language of choice, see c.name



81
82
83
# File 'lib/exchanger/elements/item.rb', line 81

def categories_with_color
  parent_folder.category_list.select { |c| categories.include?(c.name) }
end

#file_attachmentsObject



75
76
77
# File 'lib/exchanger/elements/item.rb', line 75

def file_attachments
  attachments.select { |attachment| attachment.is_a?(FileAttachment) }
end

#move_to_folder(folder) ⇒ Object



85
86
87
# File 'lib/exchanger/elements/item.rb', line 85

def move_to_folder(folder)
  Exchanger::MoveItem.run(items: [self], folder_id: folder.id)
end

#new_file_attachment(attributes = {}) ⇒ Object



71
72
73
# File 'lib/exchanger/elements/item.rb', line 71

def new_file_attachment(attributes = {})
  FileAttachment.new(attributes.merge(parent_item_id: item_id.id))
end