Class: Rospatent::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/rospatent/search.rb

Overview

Search result class to handle API responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SearchResult

Initialize a search result from API response

Parameters:

  • response (Hash)

    API response data



12
13
14
15
16
17
# File 'lib/rospatent/search.rb', line 12

def initialize(response)
  @raw_response = response
  @total = response["total"]
  @available = response["available"]
  @hits = response["hits"] || []
end

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



8
9
10
# File 'lib/rospatent/search.rb', line 8

def available
  @available
end

#hitsObject (readonly)

Returns the value of attribute hits.



8
9
10
# File 'lib/rospatent/search.rb', line 8

def hits
  @hits
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



8
9
10
# File 'lib/rospatent/search.rb', line 8

def raw_response
  @raw_response
end

#totalObject (readonly)

Returns the value of attribute total.



8
9
10
# File 'lib/rospatent/search.rb', line 8

def total
  @total
end

Instance Method Details

#any?Boolean

Check if the search has any results

Returns:

  • (Boolean)

    true if there are any hits



21
# File 'lib/rospatent/search.rb', line 21

def any? = !@hits.empty?

#countInteger

Return the number of hits in the current response

Returns:

  • (Integer)

    number of hits



25
# File 'lib/rospatent/search.rb', line 25

def count = @hits.count