Class: Rating

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
app/models/rating.rb

Overview

Read-only view of a Reviews.io product review summary (average stars,
review count, individual reviews) keyed off the underlying object's
cache key so the public site can render star badges without coupling
the view to the upstream API shape.

Instance Attribute Summary collapse

Delegated Instance Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_review_info, object = nil) ⇒ Rating

Returns a new instance of Rating.

Parameters:

  • product_review_info (Hash)

    raw review summary from Reviews.io

  • object (ActiveModel::Model, nil) (defaults to: nil)

    the object being rated



16
17
18
19
# File 'app/models/rating.rb', line 16

def initialize(product_review_info, object = nil)
  @product_review_info = product_review_info
  @object = object
end

Instance Attribute Details

#objectActiveModel::Model (readonly)

Returns:

  • (ActiveModel::Model)


10
11
12
# File 'app/models/rating.rb', line 10

def object
  @object
end

Instance Method Details

#avg_starsNumeric?

Returns:

  • (Numeric, nil)


22
23
24
# File 'app/models/rating.rb', line 22

def avg_stars
  @product_review_info[:star_avg]
end

#cache_keyObject

Alias for Object#cache_key

Returns:

  • (Object)

    Object#cache_key

See Also:



12
# File 'app/models/rating.rb', line 12

delegate :cache_key, to: :object

#product_reviewsArray?

Returns:

  • (Array, nil)


32
33
34
# File 'app/models/rating.rb', line 32

def product_reviews
  @product_review_info[:reviews]
end

#review_countInteger?

Returns:

  • (Integer, nil)


27
28
29
# File 'app/models/rating.rb', line 27

def review_count
  @product_review_info[:num]
end