Class: Workarea::Admin::Reports::ReviewsByProductViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::Reports::ReviewsByProductViewModel
- Defined in:
- app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb
Instance Method Summary collapse
Instance Method Details
#products ⇒ Object
19 20 21 22 23 |
# File 'app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb', line 19 def products @products ||= Catalog::Product.any_in( id: model.results.map { |r| r['_id'] } ).to_a end |
#results ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/view_models/workarea/admin/reports/reviews_by_product_view_model.rb', line 5 def results @results ||= model.results.map do |result| product = products.detect { |p| p.id == result['_id'] } OpenStruct.new( { product: product } .merge(result) .merge( average_rating: result['average_rating'].round(2), weighted_average_rating: result['weighted_average_rating'].round(2) ) ) end end |