Class: FederalRegister::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/federal_register/result_set.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(attributes, result_class) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #next ⇒ Object
- #previous ⇒ Object
Methods inherited from Client
Constructor Details
#initialize(attributes, result_class) ⇒ ResultSet
Returns a new instance of ResultSet.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/federal_register/result_set.rb', line 6 def initialize(attributes, result_class) @result_class = result_class @count = attributes['count'] @total_pages = attributes['total_pages'] @results = (attributes['results'] || []).map{|result| @result_class.new(result) } @description = attributes['description'] @prev_url = attributes['previous_page_url'] @next_url = attributes['next_page_url'] @errors = attributes['errors'] end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
4 5 6 |
# File 'lib/federal_register/result_set.rb', line 4 def count @count end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/federal_register/result_set.rb', line 4 def description @description end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/federal_register/result_set.rb', line 4 def errors @errors end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
4 5 6 |
# File 'lib/federal_register/result_set.rb', line 4 def results @results end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
4 5 6 |
# File 'lib/federal_register/result_set.rb', line 4 def total_pages @total_pages end |
Class Method Details
.fetch(url, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/federal_register/result_set.rb', line 27 def self.fetch(url, = {}) result_class = .delete(:result_class) response = get(url, ).parsed_response new(response, result_class) end |
Instance Method Details
#each ⇒ Object
33 34 35 |
# File 'lib/federal_register/result_set.rb', line 33 def each @results.each {|result| yield result } end |
#next ⇒ Object
19 20 21 |
# File 'lib/federal_register/result_set.rb', line 19 def next self.class.fetch(@next_url, :result_class => @result_class) if @next_url end |
#previous ⇒ Object
23 24 25 |
# File 'lib/federal_register/result_set.rb', line 23 def previous self.class.fetch(@prev_url, :result_class => @result_class) if @prev_url end |