Class: HearthstoneAPI::CardWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/hearthstone_api_utils.rb

Class Method Summary collapse

Class Method Details

.write_to_json_file(cards, filename) ⇒ Object



6
7
8
9
10
# File 'lib/hearthstone_api_utils.rb', line 6

def self.write_to_json_file cards, filename
  File.open(filename, 'w') do |file|
    file.puts JSON.dump(cards)
  end
end

.write_to_mongodb(cards, coll_name, db_name) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/hearthstone_api_utils.rb', line 12

def self.write_to_mongodb cards, coll_name, db_name
  filename = File.expand_path('../bin', File.dirname(__FILE__)) << '/tmp_hearthstone_cards'
  self.write_to_json_file cards, filename
  cmd = "mongoimport -d #{db_name} -c #{coll_name} --jsonArray #{filename}"
  puts "Running '#{cmd}'"
  `#{cmd}`
  `rm -f "#{filename}"`
end