Class: GuardianSearcher::SectionResult

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results: nil, editions: nil) ⇒ SectionResult

Returns a new instance of SectionResult.



9
10
11
12
13
14
15
16
# File 'lib/guardian_searcher/section_result.rb', line 9

def initialize(
  results: nil,
  editions: nil
)

  @results = results
  @editions = editions
end

Instance Attribute Details

#editionsObject (readonly)

Returns the value of attribute editions.



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

def editions
  @editions
end

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

Class Method Details

.parse_results(body: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/guardian_searcher/section_result.rb', line 18

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

  body = JSON.parse(body)
  response = body["response"]
  GuardianSearcher::SearchResult.new(
    results: response["results"],
    editions: response["results"][0]["editions"]
  )
end