Class: GoogleApps::Atom::MessageAttributes

Inherits:
Document
  • Object
show all
Defined in:
lib/google_apps/atom/message_attributes.rb

Constant Summary collapse

DRAFT =
'IS_DRAFT'
INBOX =
'IS_INBOX'
SENT =
'IS_SENT'
TRASH =
'IS_TRASH'
STARRED =
'IS_STARRED'
UNREAD =
'IS_UNREAD'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Document

add_type, #attrs_from_props, #build_root, #delete_node, #determine_namespaces, #find_and_update, #find_values, inherited, #make_document, #new_empty_doc, #parse, #set_instances, sub_to_meth, #type_to_s, #type_to_sym, types

Methods included from Node

#add_attributes, #add_namespaces, #add_prop_node, #check_value, #create_node, #get_content, #get_values, #node_match?

Constructor Details

#initialize(xml = nil) ⇒ MessageAttributes

Returns a new instance of MessageAttributes.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/google_apps/atom/message_attributes.rb', line 14

def initialize(xml = nil)
  super(xml)
  
  if xml
    find_labels
    get_item_property
  else
    @labels = []
    set_header
  end
end

Instance Attribute Details

#labelsObject (readonly)

Returns the value of attribute labels.



4
5
6
# File 'lib/google_apps/atom/message_attributes.rb', line 4

def labels
  @labels
end

#propertyObject

Returns the value of attribute property.



5
6
7
# File 'lib/google_apps/atom/message_attributes.rb', line 5

def property
  @property
end

Instance Method Details

#<<(value) ⇒ Object



47
48
49
# File 'lib/google_apps/atom/message_attributes.rb', line 47

def <<(value)
  add_label(value) unless @labels.include?(value)
end

#add_label(name) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/google_apps/atom/message_attributes.rb', line 38

def add_label(name)
  label = Atom::XML::Node.new 'apps:label'
  label['labelName'] = name

  @doc.root << label
  @labels << name
  @doc = parse(@doc)
end

#add_property(prop) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/google_apps/atom/message_attributes.rb', line 26

def add_property(prop)
  property = Atom::XML::Node.new 'apps:mailItemProperty'
  property['value'] = prop

  @doc.root << property
  @doc = parse(@doc)
end

#remove_label(value) ⇒ Object



51
52
53
54
# File 'lib/google_apps/atom/message_attributes.rb', line 51

def remove_label(value)
  @labels.delete(value)
  delete_node('//apps:label', labelName: [value])
end

#to_sObject



56
57
58
# File 'lib/google_apps/atom/message_attributes.rb', line 56

def to_s
  @doc.to_s
end