Sha256: 79ad5efc9d47492e7cd2a43021eac69f8f5720e96965877af9a444259734bc84

Contents?: true

Size: 1004 Bytes

Versions: 2

Compression:

Stored size: 1004 Bytes

Contents

module Harvesting
  module Models
    class Tasks < Base
      include Harvesting::Enumerable
      extend Forwardable

      attributed :per_page,
                 :total_pages,
                 :total_entries,
                 :next_page,
                 :previous_page,
                 :page,
                 :links

      attr_reader :entries

      def initialize(attrs, opts = {})
        super(attrs.reject {|k,v| k == "tasks" }, opts)
        @api_page = attrs
        @entries = attrs["tasks"].map do |entry|
          Task.new(entry, client: opts[:client])
        end
      end

      # def each
      #   @entries.each_with_index do |time_entry, index|
      #     yield(time_entry)
      #   end
      # end
      def page
        @attributes['page']
      end

      def size
        total_entries
      end

      def fetch_next_page
        new_page = page + 1
        @entries += client.tasks(page: new_page).entries
        @attributes['page'] = new_page
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
harvesting-0.2.0 lib/harvesting/models/tasks.rb
harvesting-0.1.0 lib/harvesting/models/tasks.rb