Parent

Included Modules

Class/Module Index [+]

Quicksearch

Twitter::Cursor

Attributes

attrs[R]
collection[R]
to_hash[R]

Public Class Methods

from_response(response, collection_name, klass, client, method_name, method_options) click to toggle source

Initializes a new Cursor object

@param response [Hash] @param collection_name [String, Symbol] The name of the method to return the collection @param klass [Class] The class to instantiate object in the collection @param client [Twitter::Client] @param method_name [String, Symbol] @param method_options [Hash] @return [Twitter::Cursor]

# File lib/twitter/cursor.rb, line 18
def self.from_response(response, collection_name, klass, client, method_name, method_options)
  new(response[:body], collection_name, klass, client, method_name, method_options)
end
new(attrs, collection_name, klass, client, method_name, method_options) click to toggle source

Initializes a new Cursor

@param attrs [Hash] @param collection_name [String, Symbol] The name of the method to return the collection @param klass [Class] The class to instantiate object in the collection @param client [Twitter::Client] @param method_name [String, Symbol] @param method_options [Hash] @return [Twitter::Cursor]

# File lib/twitter/cursor.rb, line 31
def initialize(attrs, collection_name, klass, client, method_name, method_options)
  @attrs = attrs
  @client = client
  @method_name = method_name
  @method_options = method_options
  @collection = Array(attrs[collection_name.to_sym]).map do |item|
    if klass
      klass.fetch_or_new(item)
    else
      item
    end
  end
  singleton_class.class_eval do
    alias_method(collection_name.to_sym, :collection)
  end
end

Public Instance Methods

all(collection=collection, cursor=next_cursor) click to toggle source

@param collection [Array] @param cursor [Integer] @return [Array]

# File lib/twitter/cursor.rb, line 51
def all(collection=collection, cursor=next_cursor)
  cursor = @client.send(@method_name.to_sym, @method_options.merge(:cursor => cursor))
  collection += cursor.collection
  cursor.last? ? collection.flatten : all(collection, cursor.next_cursor)
end
each() click to toggle source

@return [Enumerable]

# File lib/twitter/cursor.rb, line 58
def each
  all(collection, next_cursor).each do |element|
    yield element
  end
end
first() click to toggle source
Alias for: first?
first?() click to toggle source

@return [Boolean]

# File lib/twitter/cursor.rb, line 75
def first?
  previous_cursor.zero?
end
Also aliased as: first
last() click to toggle source
Alias for: last?
last?() click to toggle source

@return [Boolean]

# File lib/twitter/cursor.rb, line 81
def last?
  next_cursor.zero?
end
Also aliased as: last
next() click to toggle source
Alias for: next_cursor
next_cursor() click to toggle source
# File lib/twitter/cursor.rb, line 64
def next_cursor
  @attrs[:next_cursor] || -1
end
Also aliased as: next
previous() click to toggle source
Alias for: previous_cursor
previous_cursor() click to toggle source
# File lib/twitter/cursor.rb, line 69
def previous_cursor
  @attrs[:previous_cursor]
end
Also aliased as: previous

[Validate]

Generated with the Darkfish Rdoc Generator 2.