Class: Spaceship::Tunes::AppRatingSummary

Inherits:
TunesBase show all
Defined in:
lib/spaceship/tunes/app_ratings.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TunesBase

client

Methods inherited from Base

attr_accessor, attr_mapping, #attributes, attributes, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#five_star_rating_countInteger (readonly)

Returns total number of five star ratings recevied.

Returns:

  • (Integer)

    total number of five star ratings recevied



76
77
78
# File 'lib/spaceship/tunes/app_ratings.rb', line 76

def five_star_rating_count
  @five_star_rating_count
end

#four_star_rating_countInteger (readonly)

Returns total number of four star ratings recevied.

Returns:

  • (Integer)

    total number of four star ratings recevied



73
74
75
# File 'lib/spaceship/tunes/app_ratings.rb', line 73

def four_star_rating_count
  @four_star_rating_count
end

#one_star_rating_countInteger (readonly)

Returns total number of one star ratings recevied.

Returns:

  • (Integer)

    total number of one star ratings recevied



64
65
66
# File 'lib/spaceship/tunes/app_ratings.rb', line 64

def one_star_rating_count
  @one_star_rating_count
end

#rating_countInteger (readonly)

Returns total number of ratings recevied.

Returns:

  • (Integer)

    total number of ratings recevied



61
62
63
# File 'lib/spaceship/tunes/app_ratings.rb', line 61

def rating_count
  @rating_count
end

#review_countInteger (readonly)

Returns total number of reviews recevied.

Returns:

  • (Integer)

    total number of reviews recevied



58
59
60
# File 'lib/spaceship/tunes/app_ratings.rb', line 58

def review_count
  @review_count
end

#three_star_rating_countInteger (readonly)

Returns total number of three star ratings recevied.

Returns:

  • (Integer)

    total number of three star ratings recevied



70
71
72
# File 'lib/spaceship/tunes/app_ratings.rb', line 70

def three_star_rating_count
  @three_star_rating_count
end

#two_star_rating_countInteger (readonly)

Returns total number of two star ratings recevied.

Returns:

  • (Integer)

    total number of two star ratings recevied



67
68
69
# File 'lib/spaceship/tunes/app_ratings.rb', line 67

def two_star_rating_count
  @two_star_rating_count
end

Class Method Details

.factory(attrs) ⇒ Object

Create a new object based on a hash. This is used to create a new object based on the server response.



91
92
93
94
# File 'lib/spaceship/tunes/app_ratings.rb', line 91

def factory(attrs)
  obj = self.new(attrs)
  return obj
end

Instance Method Details

#average_ratingFloat

Returns the average rating for this summary (rounded to 2 decimal places).

Returns:

  • (Float)

    the average rating for this summary (rounded to 2 decimal places)



98
99
100
101
102
103
104
# File 'lib/spaceship/tunes/app_ratings.rb', line 98

def average_rating
  ((self.one_star_rating_count +
    (self.two_star_rating_count * 2) +
    (self.three_star_rating_count * 3) +
    (self.four_star_rating_count * 4) +
    (self.five_star_rating_count * 5)) / self.rating_count.to_f).round(2)
end