Skip to content

Instantly share code, notes, and snippets.

@Shinya-T
Created July 3, 2014 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shinya-T/cef97075590252dddc31 to your computer and use it in GitHub Desktop.
Save Shinya-T/cef97075590252dddc31 to your computer and use it in GitHub Desktop.
total.rb
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