#coding=utf-8

namespace :text do
  desc "测试文件读取存储"
  task :add => :environment do
    f = File.open("lib/output.txt", "r")

    # ... process the file
    f.each_line do |line|
      if line.include?("Your score")
        game = Game.find(151343)
        max_query_index = game.query_index - 1
        puts line
        a = line[11, line.length-1].try(:strip)
        outputs = game.outputs.where(:query_index => max_query_index)
        outputs.update_all(:text_scor => a) if outputs.present?
      end
      puts "11" + line
    end
    f.close
  end
end