Object
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
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
@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
@return [Enumerable]
# File lib/twitter/cursor.rb, line 58 def each all(collection, next_cursor).each do |element| yield element end end
@return [Boolean]
# File lib/twitter/cursor.rb, line 75 def first? previous_cursor.zero? end
@return [Boolean]
# File lib/twitter/cursor.rb, line 81 def last? next_cursor.zero? end
# File lib/twitter/cursor.rb, line 64 def next_cursor @attrs[:next_cursor] || -1 end
# File lib/twitter/cursor.rb, line 69 def previous_cursor @attrs[:previous_cursor] end
Generated with the Darkfish Rdoc Generator 2.