class XporterOnDemand::ResultSet

Attributes

endpoint[RW]
results[RW]
school[RW]

Public Class Methods

new(result_hash) click to toggle source
# File lib/xporter_on_demand/result/result_set.rb, line 8
def initialize(result_hash)
  results = create_results(result_hash)
  assign_attributes results
end

Public Instance Methods

all() click to toggle source
# 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) click to toggle source
# 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() { |result| ... } click to toggle source
# File lib/xporter_on_demand/result/result_set.rb, line 13
def each
  all.each{ |result| yield result }
end
fetch_all() click to toggle source
# 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() click to toggle source
# File lib/xporter_on_demand/result/result_set.rb, line 21
def length
  all.length
end

Private Instance Methods

create_results(result_hash) click to toggle source
# File lib/xporter_on_demand/result/result_set.rb, line 63
def create_results(result_hash)
  result_hash.map do |namespace, objects|
    type = namespace.underscore.camelize
    result_objects = objects.flat_map{ |object| create_result(type, object) }

    [namespace.underscore, result_objects]
  end.to_h
end