Class: SearchResponse

Inherits:
Struct
  • Object
show all
Defined in:
lib/dto/search/search_response.rb

Overview

Class SearchResponse represents server response on search Search API request. Server response is sent to initializer which creates object with attributes success, numResults, execTimeMs, results accessible via getters:

  • success

  • num_results

  • numResults

  • execTimeMs

  • exec_time_ms

  • results

Examples:

response = SearchResponse.new("success" => "true", "numResults" => 0, "execTimeMs" => 100, "results" => [])
response.category     # => "VAUT"
response.numResults   # => 0
response.num_results  # => 0
response.execTimeMs   # => 100
response.exec_time_ms # => 100
response.results      # => []

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

from_array, from_hash

Constructor Details

#initialize(hash = {}) ⇒ SearchResponse

Initializer receives hash as a parameter and fills object fields from it. results field is filled with array of Posting objects.



32
33
34
35
36
# File 'lib/dto/search/search_response.rb', line 32

def initialize(hash = {})
  hash.each do |key, value|
    self.send("#{key}=".to_sym, key == 'results' ? value.collect {|item| Posting.new(item)} : value )
  end
end

Instance Attribute Details

#execTimeMsObject

Returns the value of attribute execTimeMs

Returns:

  • (Object)

    the current value of execTimeMs



21
22
23
# File 'lib/dto/search/search_response.rb', line 21

def execTimeMs
  @execTimeMs
end

#numResultsObject

Returns the value of attribute numResults

Returns:

  • (Object)

    the current value of numResults



21
22
23
# File 'lib/dto/search/search_response.rb', line 21

def numResults
  @numResults
end

#resultsObject

Returns the value of attribute results

Returns:

  • (Object)

    the current value of results



21
22
23
# File 'lib/dto/search/search_response.rb', line 21

def results
  @results
end

#successObject

Returns the value of attribute success

Returns:

  • (Object)

    the current value of success



21
22
23
# File 'lib/dto/search/search_response.rb', line 21

def success
  @success
end