Created
July 3, 2014 15:31
-
-
Save Shinya-T/cef97075590252dddc31 to your computer and use it in GitHub Desktop.
total.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongo' | |
class total | |
def initialize | |
db = URI.parse(ENV['MONGOHQ_URL']) | |
db_name = db.path.gsub(/^\//, '') | |
@mongo = Mongo::Connection.new(db.host, db.port).db(db_name) | |
@mongo.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?) | |
end | |
def add(user, collection_name) | |
coll = @mongo.collection(collection_name) | |
doc = {'school_id' => user.class.school_id, 'class_id' => user.class_id, 'date' => Time.now} | |
coll.insert(doc) | |
end | |
def count_class(user, collection_name, from_date , to_date) | |
coll = @mongo.collection(collection_name) | |
coll.count('class_id' => user.class_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment