class Tinybucket::Model::Page
@see developer.atlassian.com/bitbucket/api/2/reference/meta/pagination
Paging through object collections
@!attribute [r] attrs
This attribute is a Hash object which contains 'size', 'page', 'pagelen', 'next', 'previous' key/value pairs. @return [Hash]
@!attribute [r] items
This attribute is a array of model instance created with 'values' attribute in json.
Attributes
attrs[R]
items[R]
Public Class Methods
new(json, item_klass)
click to toggle source
Initialize with json and Model
class.
@param json [Hash] @param item_klass [Class]
# File lib/tinybucket/model/page.rb, line 25 def initialize(json, item_klass) @attrs = parse_attrs(json) @items = parse_values(json, item_klass) end
Private Instance Methods
parse_attrs(json)
click to toggle source
# File lib/tinybucket/model/page.rb, line 32 def parse_attrs(json) %w(size page pagelen next previous).map do |attr| { attr.to_sym => json[attr] } end.reduce(&:merge) end
parse_values(json, item_klass)
click to toggle source
# File lib/tinybucket/model/page.rb, line 38 def parse_values(json, item_klass) return [] if json['values'].nil? || !json['values'].is_a?(Array) json['values'].map { |hash| item_klass.new(hash) } end