Class: Unsplash::SearchResult

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/unsplash/search.rb

Overview

Decorates Array of klass-type objects with total and total_pages attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decorated, klass) ⇒ SearchResult

Returns a new instance of SearchResult.


7
8
9
10
11
12
13
14
15
16
# File 'lib/unsplash/search.rb', line 7

def initialize(decorated, klass)
  @total = decorated["total"]
  @total_pages = decorated["total_pages"]

  list = decorated["results"].map do |content|
    klass.new content.to_hash
  end

  super(list)
end

Instance Attribute Details

#totalObject (readonly)

Returns the value of attribute total.


5
6
7
# File 'lib/unsplash/search.rb', line 5

def total
  @total
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.


5
6
7
# File 'lib/unsplash/search.rb', line 5

def total_pages
  @total_pages
end