class Edools::PaginatedCollection

Attributes

current_page[RW]

Our custom array to handle pagination methods

per_page[RW]

Our custom array to handle pagination methods

total_count[RW]

Our custom array to handle pagination methods

total_pages[RW]

Our custom array to handle pagination methods

Public Class Methods

new(parsed = {}) click to toggle source

The initialize method will receive the ActiveResource parsed result and set @elements.

# File lib/edools/paginated_collection.rb, line 11
def initialize(parsed = {})
  @elements = parsed[resource_key(parsed.keys)]
  @total_pages = parsed["total_pages"]
  @per_page = parsed["per_page"]
  @total_count = parsed["total_count"]
  @current_page = parsed["current_page"]
end

Private Instance Methods

resource_key(keys) click to toggle source
# File lib/edools/paginated_collection.rb, line 21
def resource_key(keys)
  (Edools.api_objects
    .collect { |klass| split_class_name_to_key_match(klass) }.flatten & keys).first
end
split_class_name_to_key_match(klass) click to toggle source
# File lib/edools/paginated_collection.rb, line 26
def split_class_name_to_key_match(klass)
  resource_key = klass.name.split("::").last.underscore.pluralize

  if resource_key.include?('_')
    [resource_key, resource_key.gsub('_')]
  else
    resource_key
  end
end