Class: GuardianSearcher::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/guardian_searcher/search_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_page: nil, results: nil, page_size: nil, pages: nil, start: nil) ⇒ SearchResult

Returns a new instance of SearchResult.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/guardian_searcher/search_result.rb', line 9

def initialize(
  current_page: nil,
  results: nil,
  page_size: nil,
  pages: nil,
  start: nil
)

  @current_page = current_page
  @results = results
  @page_size = page_size
  @pages = pages
  @start = start
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



7
8
9
# File 'lib/guardian_searcher/search_result.rb', line 7

def current_page
  @current_page
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



7
8
9
# File 'lib/guardian_searcher/search_result.rb', line 7

def page_size
  @page_size
end

#pagesObject (readonly)

Returns the value of attribute pages.



7
8
9
# File 'lib/guardian_searcher/search_result.rb', line 7

def pages
  @pages
end

#resultsObject (readonly)

Returns the value of attribute results.



7
8
9
# File 'lib/guardian_searcher/search_result.rb', line 7

def results
  @results
end

#startObject (readonly)

Returns the value of attribute start.



7
8
9
# File 'lib/guardian_searcher/search_result.rb', line 7

def start
  @start
end

Class Method Details

.parse_results(body: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/guardian_searcher/search_result.rb', line 24

def self.parse_results(body: nil)
  return unless body

  body = JSON.parse(body)
  response = body["response"]
  GuardianSearcher::SearchResult.new(
    current_page: response["currentPage"],
    results: response["results"],
    page_size: response["pageSize"],
    pages: response["pages"],
    start: response["startIndex"]
  )
end