[logaling-commit] logaling/logaling-command [improve-repository-interface] Reduce Repository#lookup arguments

Back to archive index

null+****@clear***** null+****@clear*****
Sat Feb 18 23:30:03 JST 2012


SHIMADA Koji	2012-02-18 23:30:03 +0900 (Sat, 18 Feb 2012)

  New Revision: 55da97c81ef0947dfbc4caa9be60496a3053336b

  Log:
    Reduce Repository#lookup arguments

  Modified files:
    lib/logaling/command/application.rb
    lib/logaling/glossary_db.rb
    lib/logaling/repository.rb
    spec/logaling/glossary_spec.rb
    spec/logaling/repository_spec.rb

  Modified: lib/logaling/command/application.rb (+1 -3)
===================================================================
--- lib/logaling/command/application.rb    2012-02-18 23:21:03 +0900 (85fa177)
+++ lib/logaling/command/application.rb    2012-02-18 23:30:03 +0900 (106386b)
@@ -191,9 +191,7 @@ module Logaling::Command
     method_option "no-pager", type: :boolean, default: false
     def lookup(source_term)
       @repository.index
-      terms =****@repos*****(source_term,
-                                 @config.source_language, @config.target_language,
-                                 @config.glossary)
+      terms =****@repos*****(source_term, glossary)
       unless terms.empty?
         max_str_size = terms.map{|term| term[:source_term].size}.sort.last
         run_pager

  Modified: lib/logaling/glossary_db.rb (+4 -4)
===================================================================
--- lib/logaling/glossary_db.rb    2012-02-18 23:21:03 +0900 (9dc48ad)
+++ lib/logaling/glossary_db.rb    2012-02-18 23:30:03 +0900 (420181b)
@@ -81,15 +81,15 @@ module Logaling
       end
     end
 
-    def lookup(source_term, source_language, target_language, glossary)
+    def lookup(source_term, glossary_source)
       records_selected = Groonga["translations"].select do |record|
         conditions = [record.source_term =~ source_term]
-        conditions << (record.source_language =~ source_language) if source_language
-        conditions << (record.target_language =~ target_language) if target_language
+        conditions << (record.source_language =~ glossary_source.source_language) if glossary_source.source_language
+        conditions << (record.target_language =~ glossary_source.target_language) if glossary_source.target_language
         conditions
       end
       specified_glossary = records_selected.select do |record|
-        record.glossary == glossary
+        record.glossary == glossary_source.glossary
       end
       specified_glossary.each do |record|
         record.key._score += 10

  Modified: lib/logaling/repository.rb (+2 -2)
===================================================================
--- lib/logaling/repository.rb    2012-02-18 23:21:03 +0900 (ab02c58)
+++ lib/logaling/repository.rb    2012-02-18 23:30:03 +0900 (4bb4a82)
@@ -50,12 +50,12 @@ module Logaling
       end
     end
 
-    def lookup(source_term, source_language, target_language, glossary)
+    def lookup(source_term, glossary_source)
       raise GlossaryDBNotFound unless File.exist?(logaling_db_home)
 
       terms = []
       Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
-        terms = db.lookup(source_term, source_language, target_language, glossary)
+        terms = db.lookup(source_term, glossary_source)
       end
       terms
     end

  Modified: spec/logaling/glossary_spec.rb (+2 -2)
===================================================================
--- spec/logaling/glossary_spec.rb    2012-02-18 23:21:03 +0900 (3d251a5)
+++ spec/logaling/glossary_spec.rb    2012-02-18 23:30:03 +0900 (c993432)
@@ -101,7 +101,7 @@ module Logaling
           glossary.add("delete_logaling", "てすと2", "備考")
           glossary.delete("delete_logaling", "てすと1")
           repository.index
-          @result = repository.lookup("delete_logaling", "en", "ja", project)
+          @result = repository.lookup("delete_logaling", glossary)
         end
 
         it 'should delete the bilingual pair' do
@@ -138,7 +138,7 @@ module Logaling
             glossary.add("user_logaling", "ユーザ", "備考")
             glossary.delete_all("user_logaling")
             repository.index
-            @result = repository.lookup("user_logaling", "en", "ja", project)
+            @result = repository.lookup("user_logaling", glossary)
           end
 
           it 'should delete the term' do

  Modified: spec/logaling/repository_spec.rb (+5 -5)
===================================================================
--- spec/logaling/repository_spec.rb    2012-02-18 23:21:03 +0900 (092a9cd)
+++ spec/logaling/repository_spec.rb    2012-02-18 23:30:03 +0900 (45d8f64)
@@ -39,7 +39,7 @@ module Logaling
           glossary.add("user-logaling", "ユーザー", "")
           File.stub!(:mtime).and_return(Time.now - 1)
           repository.index
-          @terms = repository.lookup("user-logaling", "en", "ja", project)
+          @terms = repository.lookup("user-logaling", glossary)
         end
 
         it 'succeed at find by term' do
@@ -55,7 +55,7 @@ module Logaling
           FileUtils.touch(tsv_path)
           File.open(tsv_path, "w"){|f| f.puts "test-logaling\tユーザー\ntest-logaling\tユーザ"}
           repository.index
-          @terms = repository.lookup("test-logaling", "en", "ja", project)
+          @terms = repository.lookup("test-logaling", glossary)
         end
 
         it 'succeed at find by term' do
@@ -79,7 +79,7 @@ module Logaling
           FileUtils.touch(glossary_path)
           glossary.add("spec_logaling", "スペック", "備考")
           repository.index
-          @terms = repository.lookup("spec_logaling", "en", "ja", "spec")
+          @terms = repository.lookup("spec_logaling", glossary)
         end
 
         it 'glossaries should be indexed' do
@@ -97,7 +97,7 @@ module Logaling
           FileUtils.touch(tsv_path)
           File.open(tsv_path, "w"){|f| f.puts "user-logaling\tユーザ"}
           repository.index
-          @terms = repository.lookup("user-logaling", "en", "ja", "spec")
+          @terms = repository.lookup("user-logaling", glossary)
         end
 
 
@@ -116,7 +116,7 @@ module Logaling
           FileUtils.touch(csv_path)
           File.open(csv_path, "w"){|f| f.puts "test_logaling,テスト"}
           repository.index
-          @terms = repository.lookup("test_logaling", "en", "ja", "spec")
+          @terms = repository.lookup("test_logaling", glossary)
         end
 
         it 'glossaries should be indexed' do




More information about the logaling-commit mailing list
Back to archive index