Class: AjaxCat::Pairs
- Inherits:
-
Object
- Object
- AjaxCat::Pairs
- Defined in:
- lib/ajax-cat/pairs.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Pairs
constructor
A new instance of Pairs.
- #list ⇒ Object
- #process_request(request, pair_name) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Pairs
Returns a new instance of Pairs.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ajax-cat/pairs.rb', line 7 def initialize(configuration) @pairs = {} unless File.exist?("#{Dir.home}/.ajax-cat/admin.db") @db = SQLite3::Database.new("#{Dir.home}/.ajax-cat/admin.db") @db.execute( " create table tasks (\n id integer primary key,\n pair varchar (30),\n name varchar (30)\n )\n SQL\n )\n @db.execute(\n <<-SQL\n create table logs (\n id integer primary key,\n task_id integer,\n email varchar (60),\n time current_timestamp,\n sentences text,\n options text,\n log text\n )\n SQL\n )\n #Task.new(id: 1, pair: \"de-en\", sentence: \"Das ist ein kleines haus\").save\n #Task.new(id: 2, pair: \"de-en\", sentence: \"Das ist ein kleines haus 2\").save\n\n #Log.new(task_id: 1, email: \"[email protected]\", time: Time.now, log: \"some log\").save\n else\n @db = SQLite3::Database.new \"\#{Dir.home}/.ajax-cat/admin.db\"\n end\n ActiveRecord::Base.establish_connection(:adapter => \"sqlite3\", :database => \"\#{Dir.home}/.ajax-cat/admin.db\")\n configuration['pairs'].each do |pair|\n @pairs[pair['name']] = MosesPair.new(pair['name'], pair['moses_path'], pair['moses_ini_path'])\n end\nend\n" |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
5 6 7 |
# File 'lib/ajax-cat/pairs.rb', line 5 def db @db end |
Instance Method Details
#list ⇒ Object
52 53 54 |
# File 'lib/ajax-cat/pairs.rb', line 52 def list @pairs.keys end |
#process_request(request, pair_name) ⇒ Object
47 48 49 50 |
# File 'lib/ajax-cat/pairs.rb', line 47 def process_request(request, pair_name) pair = @pairs[pair_name] pair.process_request(request) end |