null+****@clear*****
null+****@clear*****
Mon Jun 18 11:28:16 JST 2012
SUZUKI Miho 2012-06-18 11:28:16 +0900 (Mon, 18 Jun 2012) New Revision: 346cfefdde0a0c1a13b4f66f7641e402953bd301 https://github.com/logaling/logaling-command/commit/346cfefdde0a0c1a13b4f66f7641e402953bd301 Merged 7228757: Merge pull request #60 from logaling/refactor-structure Log: Prepare GlossaryDB#index_glossary_source Modified files: lib/logaling/glossary.rb lib/logaling/glossary_db.rb lib/logaling/glossary_source.rb Modified: lib/logaling/glossary.rb (+5 -5) =================================================================== --- lib/logaling/glossary.rb 2012-06-14 23:21:21 +0900 (db05284) +++ lib/logaling/glossary.rb 2012-06-18 11:28:16 +0900 (03ac1ba) @@ -80,15 +80,15 @@ module Logaling Logaling::GlossaryDB.open(@project.glossary_db_path, "utf8") do |db| db.recreate_table glossary_sources.each do |glossary_source| - indexed_at = File.mtime(glossary_source) - unless db.glossary_source_exist?(glossary_source, indexed_at) + indexed_at = File.mtime(glossary_source.source_path) + unless db.glossary_source_exist?(glossary_source.source_path, indexed_at) puts "now index #{@name}..." - db.index_glossary(@name, glossary_source, @source_language, @target_language) + db.index_glossary_source(glossary_source) end end glossary_string = [@name, @source_language, @target_language].join('.') indexed_glossary_sources = db.glossary_sources_related_on_glossary(glossary_string) - (indexed_glossary_sources - glossary_sources).each do |removed_glossary_source| + (indexed_glossary_sources - glossary_sources.map(&:source_path)).each do |removed_glossary_source| puts "now deindex #{@name}..." db.deindex_glossary(@name, removed_glossary_source) end @@ -100,7 +100,7 @@ module Logaling file_name = [@name, @source_language, @target_language, type].join('.') File.join(@project.glossary_source_path, file_name) end - Dir.glob(glob_condition) + Dir.glob(glob_condition).map {|source_path| GlossarySource.new(source_path, self)} end end end Modified: lib/logaling/glossary_db.rb (+18 -0) =================================================================== --- lib/logaling/glossary_db.rb 2012-06-14 23:21:21 +0900 (1e717f3) +++ lib/logaling/glossary_db.rb 2012-06-18 11:28:16 +0900 (6a69afc) @@ -67,6 +67,24 @@ module Logaling delete_glossary_source(glossary_source) end + def index_glossary_source(glossary_source) + delete_terms if offline_index? + glossary = glossary_source.glossary + + deindex_glossary(glossary.name, glossary_source.source_path) + + add_glossary_source(glossary_source.source_path, File.mtime(glossary_source.source_path)) + add_glossary(glossary.name) + GlossarySource.load(glossary_source.source_path).each do |term| + source_term = term['source_term'] + target_term = term['target_term'] + note = term['note'] + add_translation(glossary.name, glossary_source.source_path, glossary.source_language, glossary.target_language, source_term, target_term, note) + end + + create_terms if offline_index? + end + def index_glossary(glossary_name, glossary_source, source_language, target_language) delete_terms if offline_index? Modified: lib/logaling/glossary_source.rb (+1 -1) =================================================================== --- lib/logaling/glossary_source.rb 2012-06-14 23:21:21 +0900 (45841de) +++ lib/logaling/glossary_source.rb 2012-06-18 11:28:16 +0900 (4d9b88a) @@ -61,7 +61,7 @@ module Logaling glossary_source end end - attr_reader :source_path + attr_reader :source_path, :glossary def initialize(source_path, glossary) @source_path = source_path -------------- next part -------------- An HTML attachment was scrubbed... 下載