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( <<-SQL create table tasks ( id integer primary key, pair varchar (30), name varchar (30) ) SQL ) @db.execute( <<-SQL create table logs ( id integer primary key, task_id integer, email varchar (60), time current_timestamp, sentences text, options text, log text ) SQL ) #Task.new(id: 1, pair: "de-en", sentence: "Das ist ein kleines haus").save #Task.new(id: 2, pair: "de-en", sentence: "Das ist ein kleines haus 2").save #Log.new(task_id: 1, email: "[email protected]", time: Time.now, log: "some log").save else @db = SQLite3::Database.new "#{Dir.home}/.ajax-cat/admin.db" end ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "#{Dir.home}/.ajax-cat/admin.db") configuration['pairs'].each do |pair| @pairs[pair['name']] = MosesPair.new(pair['name'], pair['moses_path'], pair['moses_ini_path']) end end |
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 |