Module: FiveStar

Defined in:
lib/five-star.rb,
lib/five-star/errors.rb,
lib/five-star/version.rb,
lib/five-star/rateable.rb,
lib/five-star/base_rater.rb,
lib/five-star/configuration.rb,
lib/five-star/rating_calculator.rb

Overview

Base module for library interface

Defined Under Namespace

Modules: Rateable Classes: BaseRater, Configuration, RatingCalculator

Constant Summary collapse

RatingError =

Exception raised when error calculating occurs.

Class.new(StandardError)
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.base_raterClass

The base class of a class that gives a rating and weighting to something that is rateable. See FiveStar.rateable.

This implements the interface necessary to calculate a rating for the rateable instance. At a minimum this must be build, rating, description and weighting.

The method build will be called on each class with the argument of the instance being rated.

Examples:

class GoreRater < FiveStar.base_rater
  rating_weight 0.4

  def description
    "The Film #{film.title} has #{film.number_of_swear_words} and was rated at #{rating}"
  end

  def rating
    # calculate rating somehow
  end
end

Returns:

  • (Class)

See Also:



63
64
65
# File 'lib/five-star.rb', line 63

def base_rater
  BaseRater
end

.rateableClass

Include this in your class that can be rated - this is your domain model object that has various attributes that you need rated. Being rateable is defined as an object that has attributes on which a rating can be calculated based on varying attributes of that model.

This adds the public class and instance methods from the Rateable module.

Examples:

class Film
  include FiveStar.rateable

  rate_with GoreRater, SwearingRater, SexRater
  # ...
end

Returns:

  • (Class)

See Also:



31
32
33
# File 'lib/five-star.rb', line 31

def rateable
  Rateable
end