Class: Showroom::Search::Result
- Inherits:
-
Object
- Object
- Showroom::Search::Result
- Defined in:
- lib/showroom/models/search/result.rb
Overview
Wraps the resources.results hash from a Shopify search suggest response, exposing typed arrays for each resource kind.
Instance Method Summary collapse
-
#articles ⇒ Array<ArticleSuggestion>
Returns article suggestions from the search result.
-
#collections ⇒ Array<CollectionSuggestion>
Returns collection suggestions from the search result.
-
#initialize(results_hash, client: nil) ⇒ Result
constructor
A new instance of Result.
-
#pages ⇒ Array<PageSuggestion>
Returns page suggestions from the search result.
-
#products(order: nil) ⇒ Array<ProductSuggestion>
Returns product suggestions from the search result, optionally sorted.
-
#queries ⇒ Array<QuerySuggestion>
Returns query suggestions from the search result.
Constructor Details
#initialize(results_hash, client: nil) ⇒ Result
Returns a new instance of Result.
16 17 18 19 |
# File 'lib/showroom/models/search/result.rb', line 16 def initialize(results_hash, client: nil) @data = results_hash @client = client end |
Instance Method Details
#articles ⇒ Array<ArticleSuggestion>
Returns article suggestions from the search result.
56 57 58 |
# File 'lib/showroom/models/search/result.rb', line 56 def articles build_suggestions('articles', ArticleSuggestion) end |
#collections ⇒ Array<CollectionSuggestion>
Returns collection suggestions from the search result.
42 43 44 |
# File 'lib/showroom/models/search/result.rb', line 42 def collections build_suggestions('collections', CollectionSuggestion) end |
#pages ⇒ Array<PageSuggestion>
Returns page suggestions from the search result.
49 50 51 |
# File 'lib/showroom/models/search/result.rb', line 49 def pages build_suggestions('pages', PageSuggestion) end |
#products(order: nil) ⇒ Array<ProductSuggestion>
Returns product suggestions from the search result, optionally sorted.
31 32 33 34 35 36 37 |
# File 'lib/showroom/models/search/result.rb', line 31 def products(order: nil) validate_order!(order) suggestions = build_suggestions('products', ProductSuggestion) return suggestions unless order sort_product_suggestions(suggestions, order) end |
#queries ⇒ Array<QuerySuggestion>
Returns query suggestions from the search result.
63 64 65 |
# File 'lib/showroom/models/search/result.rb', line 63 def queries build_suggestions('queries', QuerySuggestion) end |