Module: DocBookInMongo

Extended by:
DocBookInMongo
Included in:
DocBookInMongo
Defined in:
lib/doc_book_in_mongo.rb

Instance Method Summary collapse

Instance Method Details

#file_in_mongo(filename, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/doc_book_in_mongo.rb', line 9

def file_in_mongo(filename,options={})
  session = Moped::Session.new([ "#{options[:host]}:#{options[:port]}" ])
  session.use options[:database]
  
  xml2json = File.join(File.dirname(__FILE__),'..','bin','xml2json')
  cmd = %Q(#{xml2json} #{filename})
  output = `#{cmd}`
  json = JSON.parse(output)
  doc = json['book']
  doc['_id'] = doc['id']
  session[options[:collection]].insert(doc)
end