Class: XporterOnDemand::ResultSet
- Inherits:
-
Object
- Object
- XporterOnDemand::ResultSet
- Includes:
- Enumerable, Utils
- Defined in:
- lib/xporter_on_demand/result/result_set.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#results ⇒ Object
Returns the value of attribute results.
-
#school ⇒ Object
Returns the value of attribute school.
Instance Method Summary collapse
- #all ⇒ Object
- #attach_stuff(sch, ep) ⇒ Object
- #each ⇒ Object
- #fetch_all ⇒ Object
-
#initialize(result_hash) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #length ⇒ Object
Methods included from Utils
#assign_attributes, #configure_request, #create_result, #dont_raise_exception, #handle_exceptions, #parameterize, #unwrap
Constructor Details
#initialize(result_hash) ⇒ ResultSet
Returns a new instance of ResultSet.
8 9 10 11 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 8 def initialize(result_hash) results = create_results(result_hash) assign_attributes results end |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 6 def endpoint @endpoint end |
#results ⇒ Object
Returns the value of attribute results.
6 7 8 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 6 def results @results end |
#school ⇒ Object
Returns the value of attribute school.
6 7 8 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 6 def school @school end |
Instance Method Details
#all ⇒ Object
17 18 19 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 17 def all attributes.reject{ |a| META_KEYS.include? a.camelcase }.flat_map{ |a| send(a) } end |
#attach_stuff(sch, ep) ⇒ Object
57 58 59 60 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 57 def attach_stuff(sch, ep) self.school = sch self.endpoint = ep.dup end |
#each ⇒ Object
13 14 15 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 13 def each all.each{ |result| yield result } end |
#fetch_all ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 25 def fetch_all return self unless try :pagination og_page = pagination.page_number pagination.page_count.times do |i| # Skip if we've already got this page next if og_page == i + 1 endpoint.parameters[:page] = i + 1 results_hash = create_results(school.get_endpoint(endpoint)) results_hash.each do |type, results| if META_KEYS.include? type.camelcase assign_attributes(type => results) elsif self.respond_to?(type) send(type).sort_by!(&:id) if send(type).first.respond_to?(:id) results.each do |result| if result.respond_to?(:id) && existing_result = send(type).bsearch{ |r| r.id == result.id } existing_result.update(result) else send(type).append(result) end end else assign_attributes(type => results) end end end self end |
#length ⇒ Object
21 22 23 |
# File 'lib/xporter_on_demand/result/result_set.rb', line 21 def length all.length end |