Class: Gummi::Repository::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gummi/repository/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_result, repository, per_page, page) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
12
13
14
15
16
# File 'lib/gummi/repository/result.rb', line 7

def initialize(db_result, repository, per_page, page)
  @took = db_result.took
  @total = db_result.total
  @hits = db_result.hits
  @facets = db_result.facets
  @db_records = db_result.records
  @repository = repository
  @per_page = per_page
  @page = page
end

Instance Attribute Details

#hitsObject (readonly)

Returns the value of attribute hits.



5
6
7
# File 'lib/gummi/repository/result.rb', line 5

def hits
  @hits
end

#tookObject (readonly)

Returns the value of attribute took.



5
6
7
# File 'lib/gummi/repository/result.rb', line 5

def took
  @took
end

#totalObject (readonly)

Returns the value of attribute total.



5
6
7
# File 'lib/gummi/repository/result.rb', line 5

def total
  @total
end

Instance Method Details

#facetsObject



18
19
20
21
22
# File 'lib/gummi/repository/result.rb', line 18

def facets
  @facets.each_with_object({}) do |(name, content), facets|
    facets[name] = Hash[content["terms"].collect{|term| term.values}]
  end
end

#recordsObject



24
25
26
27
# File 'lib/gummi/repository/result.rb', line 24

def records
  entities = Array(@repository.to_entity_from_db(@db_records)) if @db_records
  Leaflet::Collection.new entities, page: @page, total: total, per_page: @per_page
end