Class: BraveSearch::SummaryResult

Inherits:
Object
  • Object
show all
Defined in:
lib/brave_search/summary_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SummaryResult

Returns a new instance of SummaryResult.



7
8
9
# File 'lib/brave_search/summary_result.rb', line 7

def initialize(data)
  @raw_data = data
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



5
6
7
# File 'lib/brave_search/summary_result.rb', line 5

def raw_data
  @raw_data
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object

Support pattern matching (Ruby 3+)



33
34
35
36
37
38
39
40
41
42
# File 'lib/brave_search/summary_result.rb', line 33

def deconstruct_keys(keys)
  hash = {
    summary: summary,
    key: key,
    status: status,
    type: type,
    enriched_results: enriched_results
  }
  keys ? hash.slice(*keys) : hash
end

#enriched_resultsObject



27
28
29
30
# File 'lib/brave_search/summary_result.rb', line 27

def enriched_results
  results = @raw_data.dig(:summarizer, :enriched_results) || []
  results.map { |result| EnrichedResult.new(result) }
end

#keyObject



15
16
17
# File 'lib/brave_search/summary_result.rb', line 15

def key
  @raw_data.dig(:summarizer, :key)
end

#statusObject



19
20
21
# File 'lib/brave_search/summary_result.rb', line 19

def status
  @raw_data.dig(:summarizer, :status)
end

#summaryObject



11
12
13
# File 'lib/brave_search/summary_result.rb', line 11

def summary
  @raw_data.dig(:summarizer, :summary) || []
end

#to_hObject



44
45
46
# File 'lib/brave_search/summary_result.rb', line 44

def to_h
  @raw_data
end

#typeObject



23
24
25
# File 'lib/brave_search/summary_result.rb', line 23

def type
  @raw_data.dig(:summarizer, :type)
end