Class: Gummi::DbLayer::Document::Search::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gummi/db_layer/document/search/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, converter, per_page, page) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gummi/db_layer/document/search/result.rb', line 9

def initialize(response, converter, per_page, page)
  @success   = !!response
  @response  = Hashie::Mash.new response
  @took      = @response.took
  @total     = @response.hits.total if @response.hits
  @hits      = @response.hits.hits  if @response.hits
  @facets    = @response.facets || Hashie::Mash.new
  @converter = converter
  @per_page  = per_page
  @page      = page
end

Instance Attribute Details

#facetsObject (readonly)

Returns the value of attribute facets.



7
8
9
# File 'lib/gummi/db_layer/document/search/result.rb', line 7

def facets
  @facets
end

#tookObject (readonly)

Returns the value of attribute took.



7
8
9
# File 'lib/gummi/db_layer/document/search/result.rb', line 7

def took
  @took
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/gummi/db_layer/document/search/result.rb', line 7

def total
  @total
end

Instance Method Details

#documentsObject



21
22
23
24
25
26
# File 'lib/gummi/db_layer/document/search/result.rb', line 21

def documents
  @documents ||= begin
    documents = Array(converter.hits_to_documents(hits)) if hits
    Leaflet::Collection.new documents, total: total, page: page, per_page: per_page
  end
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/gummi/db_layer/document/search/result.rb', line 28

def success?
  @success
end