Class: Orias::Response

Inherits:
Base
  • Object
show all
Defined in:
lib/orias/response.rb

Overview

Dedicated to search response handling

Constant Summary collapse

VALID_TYPES =
[:intermediary_search].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Response

Initialize an Orias::Response instance



12
13
14
15
16
# File 'lib/orias/response.rb', line 12

def initialize(attributes = {})
  super
  self.process_raw_response! if results.nil?
  self.check_type
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



9
10
11
# File 'lib/orias/response.rb', line 9

def raw
  @raw
end

#raw_hashObject

Returns the value of attribute raw_hash.



9
10
11
# File 'lib/orias/response.rb', line 9

def raw_hash
  @raw_hash
end

#resultsObject

Returns the value of attribute results.



9
10
11
# File 'lib/orias/response.rb', line 9

def results
  @results
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/orias/response.rb', line 9

def type
  @type
end

Class Method Details

.merge(instances) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/orias/response.rb', line 59

def merge(instances)
  if instances.map(&:type).uniq.compact.length != 1
    raise 'Orias::Response - Error merging Orias::Response collection.'
  end

  self.new(
    raw: instances.map(&:raw),
    raw_hash: instances.map(&:raw_hash),
    results: instances.map(&:results).flatten,
    type: instances.map(&:type).uniq.first
  )
end