Class: GProv::Provision::Feed
- Inherits:
-
Object
- Object
- GProv::Provision::Feed
- Defined in:
- lib/gprov/provision/feed.rb
Instance Method Summary collapse
-
#fetch(&block) ⇒ Object
Retrieve all entries in a feed, represented as nokogiri elements.
-
#initialize(connection, url, xpath) ⇒ Feed
constructor
A new instance of Feed.
-
#results ⇒ Object
If no results are available, fetch them.
Constructor Details
#initialize(connection, url, xpath) ⇒ Feed
Returns a new instance of Feed.
11 12 13 14 15 16 17 |
# File 'lib/gprov/provision/feed.rb', line 11 def initialize(connection, url, xpath) @connection = connection @url = url @xpath = xpath @results = [] end |
Instance Method Details
#fetch(&block) ⇒ Object
Retrieve all entries in a feed, represented as nokogiri elements. Takes an optional block and yields to it each successive page of results retrieved. Returns all of the entries in the feed.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gprov/provision/feed.rb', line 22 def fetch(&block) link = @url until link.nil? document = retrieve(link) results = parse(document) link = results[:nextpage] entries = results[:entries] yield entries if block_given? end @results end |
#results ⇒ Object
If no results are available, fetch them. Else return what data we have already downloaded.
38 39 40 41 |
# File 'lib/gprov/provision/feed.rb', line 38 def results fetch unless @results @results end |