Sha256: 51a000d0f7ebfad0b31ada485b6b675e677b21229b5c6dbf66ba39e9047d1c03

Contents?: true

Size: 978 Bytes

Versions: 13

Compression:

Stored size: 978 Bytes

Contents

=begin rdoc
  Videojuicer::Resource::Collection is an array extension returned by many common actions within
  the Videojuicer SDK. Any request that returns paginated data, or a subset of your query results,
  will return a Collection object containing the object subset, with some additional pagination
  data.
=end

module Videojuicer
  module Resource
    class Collection < ::Array
      
      attr_accessor :limit
      attr_accessor :offset
      attr_accessor :total
      
      def initialize(objects, total, offset, limit)
        clear
        objects.each {|o| self << o }
        self.total = total
        self.offset = offset
        self.limit = limit
      end
      
      def page_count
        return 1 if limit.nil? or total.nil? or total < 1
        (total.to_f/limit.to_f).ceil
      end
      
      def page_number
        return 1 if limit.nil? or offset.nil? or offset < 1
        ((offset+1).to_f/limit.to_f).ceil
      end
      
    end 
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vj-sdk-0.7.1 lib/videojuicer/resource/collection.rb
vj-sdk-0.7.0 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.9 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.8 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.7 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.5 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.4 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.3 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.1 lib/videojuicer/resource/collection.rb
vj-sdk-0.6.0 lib/videojuicer/resource/collection.rb
vj-sdk-0.5.6 lib/videojuicer/resource/collection.rb
vj-sdk-0.5.5 lib/videojuicer/resource/collection.rb
vj-sdk-0.5.4 lib/videojuicer/resource/collection.rb