Module: GoogleAppsOauth2::Atom::Node

Included in:
Document
Defined in:
lib/google_apps_oauth2/atom/node.rb

Instance Method Summary collapse

Instance Method Details

#add_attributes(node, attributes) ⇒ Object

add_attributes adds the specified attributes to the given node. It takes a LibXML::XML::Node and an array of name, value attribute pairs.

add_attribute node, [[‘title’, ‘emperor’], [‘name’, ‘Napoleon’]]

add_attribute returns the modified node.



30
31
32
33
34
35
36
# File 'lib/google_apps_oauth2/atom/node.rb', line 30

def add_attributes(node, attributes)
  attributes.each do |attribute|
    node.attributes[attribute[0]] = attribute[1]
  end

  node
end

#check_value(value) ⇒ Object

Parameters:

  • value (String)

Returns:



45
46
47
48
49
50
51
52
53
54
# File 'lib/google_apps_oauth2/atom/node.rb', line 45

def check_value(value)
  case value
    when 'true'
      true
    when 'false'
      false
    else
      value
  end
end

#create_node(properties) ⇒ Object

create_node takes a hash of properties from which to build the XML node. The properties hash must have a :type key, it is also possible to pass an :attrs key with an array of attribute name, value pairs.

create_node type: ‘apps:property’, attrs: [[‘name’, ‘Tim’], [‘userName’, ‘[email protected]’]]

create_node returns an Atom::XML::Node with the specified properties.



14
15
16
17
18
19
20
# File 'lib/google_apps_oauth2/atom/node.rb', line 14

def create_node(properties)
  if properties[:attrs]
    add_attributes Atom::XML::Node.new(properties[:type]), properties[:attrs]
  else
    Atom::XML::Node.new properties[:type]
  end
end