Class: Gummi::RepositoryLayer::Repository::Result
- Inherits:
-
Object
- Object
- Gummi::RepositoryLayer::Repository::Result
- Defined in:
- lib/gummi/repository_layer/repository/result.rb
Instance Attribute Summary collapse
-
#took ⇒ Object
readonly
Returns the value of attribute took.
Instance Method Summary collapse
- #facets ⇒ Object
-
#initialize(search_result, converter) ⇒ Result
constructor
A new instance of Result.
-
#method_missing(method_name, *args) ⇒ Object
Leaflet::Collection has many methods we want to make use of.
- #records ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(search_result, converter) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 14 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 8 def initialize(search_result, converter) @success = search_result.success? @search_result = search_result @took = @search_result.took if @search_result @documents = @search_result.documents if @search_result @converter = converter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Leaflet::Collection has many methods we want to make use of. E.g. kaminari and will_paginate support. Also, we want to have Enumerable and #decorate at our fingertips.
50 51 52 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 50 def method_missing(method_name, *args) records.send method_name, *args end |
Instance Attribute Details
#took ⇒ Object (readonly)
Returns the value of attribute took.
6 7 8 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 6 def took @took end |
Instance Method Details
#facets ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 16 def facets return unless search_result.facets @facets ||= begin result = {} search_result.facets.each do |(name, content)| case content['_type'] when 'terms' result[name] = Hash[content.terms.map(&:values)] when 'statistical' content.each do |k, v| result[k] = v end end end Hashie::Mash.new result end end |
#records ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 34 def records @records ||= begin # Passing through the Leaflet Collection, but converting the records. documents.map! { |document| converter.db_instance_to_entity(document) } documents end end |
#success? ⇒ Boolean
42 43 44 |
# File 'lib/gummi/repository_layer/repository/result.rb', line 42 def success? @success end |