Id like to create a model in rails that does not correlate to a table in the database. Instead the model should dynamically pull aggregrate data about other models.
Example:
I have a Restaurant model stored in the restaurants table in the DB. Id like to have a RestaurantStats model where i can run a RestaurantStats.find_total_visitors, or RestaurantStats.find_time_spent etc... on it and it returns a set of RestaurantStats models each with:
[:restaurant_id, :stat_value]
Obviously in each find... method that stat_value will mean something different (for find_time_spent it will be seconds spent, for find_total_visitors it will be number of visitors). The idea will be to return the top 100 restaurants by time spent, or total visitors.
So far im creating a model (not inherited from ActiveRecord)
class RestaurantStats
attr_reader :restaurant_id
attr_reader :stat_value
def self.find_total_visitors ...
def self.find_time_spent ...
end
The question is how do define the find_total_visitors, find_time_spent functions in a rails y way so that it will populate the restaurant_id, stat_value fields?