Class Jmdict::ImportSentencesListener
In: lib/jmdict/import_sentences_listener.rb
Parent: Jmdict::ImportCsvListener

Methods

new   read_line  

Constants

COLUMN_REFERENCE_ID = 0
COLUMN_LANGUAGE = 1
COLUMN_SENTENCE = 2

Public Class methods

[Source]

    # File lib/jmdict/import_sentences_listener.rb, line 7
 7:   def initialize(filename, version, maximum_parsed = nil)
 8:     super(filename, version, maximum_parsed)
 9: 
10:     @source_description     = 'tatoeba version [' + version + '] imported on ' + DateTime.now.to_s
11:   end

Public Instance methods

[Source]

    # File lib/jmdict/import_sentences_listener.rb, line 13
13:   def read_line(line)
14:     
15:     begin
16:       if line[COLUMN_SENTENCE]
17:         iso_639_code         = Language.convert_to_iso_639_code(line[COLUMN_LANGUAGE])
18:         language             = Language.find_by_iso_639_code(iso_639_code)
19:         unless language
20:           language = Language.new
21:           language.iso_639_code = iso_639_code
22:           language.language     = iso_639_code
23:           language.save!
24:           language.reload
25:         end
26:         
27:         sentence                    = Sentence.new
28:         sentence.language_id        = language.id
29:         sentence.source_description = @source_description
30:         sentence.source_tag         = line[COLUMN_REFERENCE_ID]
31:         sentence.sentence           = line[COLUMN_SENTENCE].gsub(/\\/,'')
32:         
33:         @records << sentence
34:       else
35:         Rails.logger.error("Insufficient information to create a sentence [#{line.inspect}]")
36:       end
37:     rescue => exception
38:       Rails.logger.error(exception)
39:     end
40:     
41:   end

[Validate]