Class: GoogleAppsOauth2::Atom::Feed
- Defined in:
- lib/google_apps_oauth2/atom/feed.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
Instance Method Summary collapse
-
#add_category(content_array) ⇒ Object
add_category adds the proper atom:category node to the content_array.
- #entries_from(properties) ⇒ Object
-
#entry_wrap(content_array) ⇒ Object
entry_wrap adds atom:entry opening and closing tags to the provided content_array and the beginning and end.
-
#grab_elements(content_array, filter) ⇒ Object
grab_elements applies the specified filter to the provided array.
-
#initialize(body) ⇒ Feed
constructor
A new instance of Feed.
-
#new_doc(content_array, filters) ⇒ Object
new_doc creates a new Atom document from the data provided in the feed.
-
#node_to_ary(node) ⇒ Object
node_to_ary converts a Atom::XML::Node to an array.
- #set_next_page(node) ⇒ Object
Methods inherited from Document
#find_values, #parse, #set_instances
Methods included from Node
#add_attributes, #check_value, #create_node
Constructor Details
#initialize(body) ⇒ Feed
Returns a new instance of Feed.
5 6 7 8 9 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 5 def initialize(body) super(body) @items = entries_from(document: @doc, entry_tag: 'entry') end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 4 def doc @doc end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
4 5 6 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 4 def items @items end |
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
4 5 6 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 4 def next_page @next_page end |
Instance Method Details
#add_category(content_array) ⇒ Object
add_category adds the proper atom:category node to the content_array
add_category content_array, ‘user’
add_category returns the modified content_array
60 61 62 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 60 def add_category(content_array) content_array.unshift(create_node(type: 'atom:category', attrs: Atom::CATEGORY[:user]).to_s) end |
#entries_from(properties) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 11 def entries_from(properties) properties[:document].root.inject([]) do |results, entry| if entry.name == properties[:entry_tag] results << new_doc(node_to_ary(entry), ['apps:', 'atom:', 'gd:']) end set_next_page(entry) if entry.name == 'link' and entry.attributes[:rel] == 'next' results end end |
#entry_wrap(content_array) ⇒ Object
entry_wrap adds atom:entry opening and closing tags to the provided content_array and the beginning and end.
entry_wrap content_array
entry_wrap returns an array with an opening atom:entry element prepended to the front and a closing atom:entry tag appended to the end.
85 86 87 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 85 def entry_wrap(content_array) content_array.unshift(Atom::ENTRY_TAG[0]).push(Atom::ENTRY_TAG[1]) end |
#grab_elements(content_array, filter) ⇒ Object
grab_elements applies the specified filter to the provided array. Google’s feed provides a lot of data that we don’t need in an entry document.
grab_elements content_array, ‘apps:’
grab_elements returns an array of items from content_array that match the given filter.
72 73 74 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 72 def grab_elements(content_array, filter) content_array.grep(Regexp.new filter) end |
#new_doc(content_array, filters) ⇒ Object
new_doc creates a new Atom document from the data provided in the feed. new_doc takes a type, an array of content to be placed into the document as well as an array of filters.
new_doc ‘user’, content_array, [‘apps:’]
new_doc returns an GoogleApps::Atom document of the specified type.
44 45 46 47 48 49 50 51 52 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 44 def new_doc(content_array, filters) content_array = filters.map do |filter| grab_elements(content_array, filter) end add_category(content_array) Atom.send :user, entry_wrap(content_array.flatten).join("\n") end |
#node_to_ary(node) ⇒ Object
node_to_ary converts a Atom::XML::Node to an array.
node_to_ary node
node_to_ary returns the string representation of the given node split on n.
31 32 33 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 31 def node_to_ary(node) node.to_s.split("\n") end |
#set_next_page(node) ⇒ Object
21 22 23 |
# File 'lib/google_apps_oauth2/atom/feed.rb', line 21 def set_next_page(node) @next_page = node.attributes[:href] end |