Class: GoogleAppsOauth2::Atom::Document
- Inherits:
-
Object
- Object
- GoogleAppsOauth2::Atom::Document
- Includes:
- Node
- Defined in:
- lib/google_apps_oauth2/atom/document.rb
Instance Method Summary collapse
-
#find_values ⇒ Object
find_values searches @doc and assigns any values to their corresponding instance variables.
-
#initialize(doc, map = {}) ⇒ Document
constructor
A new instance of Document.
- #parse(xml) ⇒ Object
- #set_instances(intersect, node) ⇒ Object
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_values ⇒ Object
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
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 |