class Newznab::Api::List

Enumerable list for multiple results

Attributes

cvos[R]
limit[R]
offset[R]
total_count[R]

Public Class Methods

new(resp, options) click to toggle source

@since 0.1.0

# File lib/newznab/api/list.rb, line 16
def initialize(resp, options)
  update_ivals(resp)

  if options.has_key? :limit
    @limit = options[:limit]
  end
end

Public Instance Methods

each() { |c| ... } click to toggle source

@since 0.1.0

# File lib/newznab/api/list.rb, line 25
def each
  @cvos.each { |c| yield c }
end
has_more?() click to toggle source

Returns if there are more pages to load @return [true, false] @since 0.1.0

# File lib/newznab/api/list.rb, line 46
def has_more?
  self.total_pages > self.page ? true : false
end
page() click to toggle source

Returns the current page the object is on @return [Integer] @since 0.1.0

# File lib/newznab/api/list.rb, line 32
def page
  (self.offset / self.limit) + 1
end
total_pages() click to toggle source

Returns the total number of pages available @return [Integer] Total number of pages @since 0.1.0

# File lib/newznab/api/list.rb, line 39
def total_pages
  (self.total_count / self.limit) + 1
end

Protected Instance Methods

method_missing(id, *args) click to toggle source

@since 0.1.0

Calls superclass method
# File lib/newznab/api/list.rb, line 68
def method_missing(id, *args)
  begin
    if @_attributes.has_key? id.to_s
      @_attributes[id.to_s]
    elsif @cvos.respond_to? id
      @cvos.method(id).call(*args)
    else
      super
    end
  end
end
respond_to_missing?(id, *args) click to toggle source

@since 0.1.0

Calls superclass method
# File lib/newznab/api/list.rb, line 81
def respond_to_missing?(id, *args)
  begin
    if @_attributes.has_key? id.to_s
      true
    elsif @cvos.respond_to? id
      true
    else
      super
    end
  end
end
update_ivals(new_cvol) click to toggle source

Updates array list to new values @param new_cvol [Hash] Response hash from {Newznab::Api} @since 0.1.0

# File lib/newznab/api/list.rb, line 56
def update_ivals(new_cvol)
  @_attributes = new_cvol['@attributes']

  if new_cvol.has_key?('channel') && new_cvol['channel'].has_key?('response')
    @total_count = new_cvol['channel']['response']['@attributes']['total'].to_i
    @offset = new_cvol['channel']['response']['@attributes']['offset'].to_i

    @cvos = new_cvol['channel']['item']
  end
end