Class: Nzbn::Models::SearchResponse

Inherits:
Base
  • Object
show all
Defined in:
lib/nzbn/models/search_response.rb

Overview

Paginated search response

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_h, #to_json

Constructor Details

#initialize(attributes = {}, item_class: nil) ⇒ SearchResponse

Returns a new instance of SearchResponse.



9
10
11
12
# File 'lib/nzbn/models/search_response.rb', line 9

def initialize(attributes = {}, item_class: nil)
  super(attributes)
  @items = parse_items(attributes['items'], item_class) if item_class
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def items
  @items
end

Returns the value of attribute links.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def links
  @links
end

#pageObject

Returns the value of attribute page.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def page
  @page
end

#page_sizeObject

Returns the value of attribute page_size.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def page_size
  @page_size
end

#sort_byObject

Returns the value of attribute sort_by.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def sort_by
  @sort_by
end

#sort_orderObject

Returns the value of attribute sort_order.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def sort_order
  @sort_order
end

#total_itemsObject

Returns the value of attribute total_items.



7
8
9
# File 'lib/nzbn/models/search_response.rb', line 7

def total_items
  @total_items
end

Instance Method Details

#countObject Also known as: size, length



34
35
36
# File 'lib/nzbn/models/search_response.rb', line 34

def count
  items&.length || 0
end

#each(&block) ⇒ Object



14
15
16
# File 'lib/nzbn/models/search_response.rb', line 14

def each(&block)
  items.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/nzbn/models/search_response.rb', line 30

def empty?
  items.nil? || items.empty?
end

#firstObject



22
23
24
# File 'lib/nzbn/models/search_response.rb', line 22

def first
  items.first
end

#lastObject



26
27
28
# File 'lib/nzbn/models/search_response.rb', line 26

def last
  items.last
end

#map(&block) ⇒ Object



18
19
20
# File 'lib/nzbn/models/search_response.rb', line 18

def map(&block)
  items.map(&block)
end