 fs = require 'fs'
 path = require 'path'
 
-generateUid = ->
-	s4 = ->
-		(((1+Math.random())*0x10000)|0).toString(16).substring(1)
+class noteddb
+	constructor: (@notebookdir) ->
+
+	generateUid: ->
+		s4 = ->
+			(((1+Math.random())*0x10000)|0).toString(16).substring(1)
  
-	(s4() + s4() + s4() + s4()).toLowerCase()
-
-
-class db
-	constructor: (@notebookdir) ->
+		(s4() + s4() + s4() + s4()).toLowerCase()
 
 	###
 	# Finds the filename of a particular note id

	###
	deleteNote: (id) ->
		fs.unlink path.join(@notebookdir, @filenameNote(id))

	# @return {String} id The new notebook id
	###
	createNotebook: (name) ->
		id = @generateUid()

		# there's a 16^16 chance of conflicting, but hey
		while fs.existsSync(path.join(@notebookdir, id  + ".json"))
			id = @generateUid()

		fs.writeFile path.join(@notebookdir, id + ".json"),
			JSON.stringify {
