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) ⇒ Result
constructor
A new instance of Result.
-
#pages ⇒ Array<PageSuggestion>
Returns page suggestions from the search result.
-
#products ⇒ Array<ProductSuggestion>
Returns product suggestions from the search result.
-
#queries ⇒ Array<QuerySuggestion>
Returns query suggestions from the search result.
Constructor Details
#initialize(results_hash) ⇒ Result
Returns a new instance of Result.
15 16 17 |
# File 'lib/showroom/models/search/result.rb', line 15 def initialize(results_hash) @data = results_hash end |
Instance Method Details
#articles ⇒ Array<ArticleSuggestion>
Returns article suggestions from the search result.
43 44 45 |
# File 'lib/showroom/models/search/result.rb', line 43 def articles @data.fetch('articles', []).map { |h| ArticleSuggestion.new(h) } end |
#collections ⇒ Array<CollectionSuggestion>
Returns collection suggestions from the search result.
29 30 31 |
# File 'lib/showroom/models/search/result.rb', line 29 def collections @data.fetch('collections', []).map { |h| CollectionSuggestion.new(h) } end |
#pages ⇒ Array<PageSuggestion>
Returns page suggestions from the search result.
36 37 38 |
# File 'lib/showroom/models/search/result.rb', line 36 def pages @data.fetch('pages', []).map { |h| PageSuggestion.new(h) } end |
#products ⇒ Array<ProductSuggestion>
Returns product suggestions from the search result.
22 23 24 |
# File 'lib/showroom/models/search/result.rb', line 22 def products @data.fetch('products', []).map { |h| ProductSuggestion.new(h) } end |
#queries ⇒ Array<QuerySuggestion>
Returns query suggestions from the search result.
50 51 52 |
# File 'lib/showroom/models/search/result.rb', line 50 def queries @data.fetch('queries', []).map { |h| QuerySuggestion.new(h) } end |