class Myfinance::Entities::Collection

A wrapper to Myfinance collection returns from API. This wrapper represents a collection and it's responsible for processing pagination information as well.

Constants

PAGE_REGEX

Attributes

collection[R]
headers[R]
response[R]

Public Class Methods

build(response) click to toggle source
# File lib/myfinance/entities/collection.rb, line 23
def self.build(response)
  new(response).build
end
new(response) click to toggle source
# File lib/myfinance/entities/collection.rb, line 13
def initialize(response)
  @response = response
  @collection = []
  @headers = begin
               response.headers["Link"].split(",")
             rescue
               []
             end
end

Public Instance Methods

build() click to toggle source
# File lib/myfinance/entities/collection.rb, line 27
def build
  build_collection
  self
end
first_page() click to toggle source
# File lib/myfinance/entities/collection.rb, line 44
def first_page
  page_for(:first)
end
last_page() click to toggle source
# File lib/myfinance/entities/collection.rb, line 36
def last_page
  page_for(:last)
end
next_page() click to toggle source
# File lib/myfinance/entities/collection.rb, line 32
def next_page
  page_for(:next)
end
previous_page() click to toggle source
# File lib/myfinance/entities/collection.rb, line 40
def previous_page
  page_for(:prev)
end

Private Instance Methods

build_collection() click to toggle source
# File lib/myfinance/entities/collection.rb, line 60
def build_collection
  raise NotImplementedError
end
page_for(page_rel) click to toggle source
# File lib/myfinance/entities/collection.rb, line 50
def page_for(page_rel)
  header_link_for(page_rel).match(PAGE_REGEX)[1].to_i
rescue
  nil
end