class NexaasID::Entities::Collection

Constants

PAGE_REGEX

Attributes

total[R]

Public Class Methods

build(response, entity_class) click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 16
def self.build(response, entity_class)
  self.new(response, entity_class).build
end
new(response, entity_class) click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 9
def initialize(response, entity_class)
  @response = response
  @entity_class = entity_class
  @total = parsed_body['count'].to_i
  @collection = []
 end

Public Instance Methods

build() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 20
def build
  build_collection
  self
end
next_page() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 25
def next_page
  page_for('next')
end
previous_page() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 29
def previous_page
  page_for('previous')
end
to_a() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 33
def to_a
  @collection.clone
end

Private Instance Methods

build_collection() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 44
def build_collection
  parsed_body['collection'].each do |attributes|
    @collection.push(@entity_class.new(attributes))
  end
end
page_for(page_rel) click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 39
def page_for(page_rel)
  match = parsed_body[page_rel].match(PAGE_REGEX)
  return match[1].to_i if match
end
parsed_body() click to toggle source
# File lib/nexaas_id/entities/collection.rb, line 50
def parsed_body
  @parsed_body ||= @response.parsed
end