Sha256: 03c08673896f1593ade5a64cfba05a69081b24b29214a860925684e7d5ef64e9

Contents?: true

Size: 867 Bytes

Versions: 2

Compression:

Stored size: 867 Bytes

Contents

class Recordings
  def initialize(recordings)
    @recordings = recordings
    @offset = 0
    @limit = nil
  end

  def limit(size)
    @limit = size
    self
  end

  def offset(number)
    @offset = number
    self
  end

  def unscope(restriction)
    case restriction
    when :offset then @offset = 0
    when :limit  then @limit  = nil
    end

    self
  end


  def [](index)
    slice[index]
  end

  def count
    slice.size
  end
  alias :size :count

  def include?(record)
    slice.include?(record)
  end


  private
    def slice
      @recordings[@offset..(@limit ? @offset + (@limit - 1) : -1)]
    end
end

class Recording
  def self.all(count = 120)
    Recordings.new(count.times.collect { |i| new(i) })
  end

  attr_reader :number

  def initialize(number)
    @number = 1
  end

  def ==(comparison)
    @number == comparison.number
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geared_pagination-0.2 test/recording_stubs.rb
geared_pagination-0.1 test/recording_stubs.rb