BigW Consortium Gitlab

page.rb 701 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
module Bitbucket
  class Page
    attr_reader :attrs, :items

    def initialize(raw, type)
      @attrs = parse_attrs(raw)
      @items = parse_values(raw, representation_class(type))
    end

    def next?
      attrs.fetch(:next, false)
    end

    def next
      attrs.fetch(:next)
    end

    private

    def parse_attrs(raw)
21
      raw.slice(*%w(size page pagelen next previous)).symbolize_keys
22 23
    end

24
    def parse_values(raw, bitbucket_rep_class)
25
      return [] unless raw['values'] && raw['values'].is_a?(Array)
Valery Sizov committed
26

27
      bitbucket_rep_class.decorate(raw['values'])
28 29 30
    end

    def representation_class(type)
Stan Hu committed
31
      Bitbucket::Representation.const_get(type.to_s.camelize)
32 33 34
    end
  end
end