Class: GoogleAppsOauth2::Atom::Document

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/google_apps_oauth2/atom/document.rb

Direct Known Subclasses

Feed, User

Instance Method Summary collapse

Methods included from Node

#add_attributes, #check_value, #create_node

Constructor Details

#initialize(doc, map = {}) ⇒ Document

Returns a new instance of Document.



6
7
8
9
# File 'lib/google_apps_oauth2/atom/document.rb', line 6

def initialize(doc, map = {})
  @doc = parse(doc)
  @map = map
end

Instance Method Details

#find_valuesObject

find_values searches @doc and assigns any values to their corresponding instance variables. This is useful when we’ve been given a string of XML and need internal consistency in the object.

find_values



22
23
24
25
26
27
# File 'lib/google_apps_oauth2/atom/document.rb', line 22

def find_values
  @doc.root.each do |entry|
    intersect = @map.keys & entry.attributes.to_h.keys.map(&:to_sym)
    set_instances(intersect, entry) unless intersect.empty?
  end
end

#parse(xml) ⇒ Object



11
12
13
14
# File 'lib/google_apps_oauth2/atom/document.rb', line 11

def parse(xml)
  document = Atom::XML::Document.string(xml)
  Atom::XML::Parser.document(document).parse
end

#set_instances(intersect, node) ⇒ Object

Parameters:

  • intersect (Array)
  • node (LibXML::XML::Node)
  • map (Hash)

Returns:



39
40
41
42
43
# File 'lib/google_apps_oauth2/atom/document.rb', line 39

def set_instances(intersect, node)
  intersect.each do |attribute|
    instance_variable_set "@#{@map[attribute]}", check_value(node.attributes[attribute])
  end
end