[logaling-commit] logaling/logaling-command [refactor-structure] Reduce method: GlossaryDB#get_bilingual_pair_with_note

Back to archive index

null+****@clear***** null+****@clear*****
Fri Jun 8 18:55:46 JST 2012


SHIMADA Koji	2012-06-08 18:55:46 +0900 (Fri, 08 Jun 2012)

  New Revision: b0ec7ac1a12968dc14c620a025d3ae5f5be362a6

  Log:
    Reduce method: GlossaryDB#get_bilingual_pair_with_note
    
    merge to GlossaryDB#get_bilingual_pair

  Modified files:
    lib/logaling/glossary_db.rb
    lib/logaling/repository.rb

  Modified: lib/logaling/glossary_db.rb (+15 -22)
===================================================================
--- lib/logaling/glossary_db.rb    2012-06-08 09:43:17 +0900 (446f5ff)
+++ lib/logaling/glossary_db.rb    2012-06-08 18:55:46 +0900 (c99fc3a)
@@ -171,30 +171,23 @@ module Logaling
       records_raw.expression.close
     end
 
-    def get_bilingual_pair(source_term, target_term, glossary)
+    def get_bilingual_pair(source_term, target_term, glossary, note=nil)
       records = Groonga["translations"].select do |record|
-        [
-          record.glossary == glossary,
-          record.source_term == source_term,
-          record.target_term == target_term
-        ]
-      end
-
-      struct_result(records)
-    ensure
-      records.expression.close
-    end
-
-    def get_bilingual_pair_with_note(source_term, target_term, note, glossary)
-      records = Groonga["translations"].select do |record|
-        [
-          record.glossary == glossary,
-          record.source_term == source_term,
-          record.target_term == target_term,
-          record.note == note
-        ]
+        if note
+          [
+            record.glossary == glossary,
+            record.source_term == source_term,
+            record.target_term == target_term,
+            record.note == note
+          ]
+        else
+          [
+            record.glossary == glossary,
+            record.source_term == source_term,
+            record.target_term == target_term
+          ]
+        end
       end
-
       struct_result(records)
     ensure
       records.expression.close

  Modified: lib/logaling/repository.rb (+1 -1)
===================================================================
--- lib/logaling/repository.rb    2012-06-08 09:43:17 +0900 (70f86b0)
+++ lib/logaling/repository.rb    2012-06-08 18:55:46 +0900 (9f12854)
@@ -153,7 +153,7 @@ module Logaling
 
       terms = []
       Logaling::GlossaryDB.open(logaling_db_home, "utf8") do |db|
-        terms = db.get_bilingual_pair_with_note(source_term, target_term, note, glossary)
+        terms = db.get_bilingual_pair(source_term, target_term, glossary, note)
       end
 
       if terms.size > 0




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