[logaling-commit] logaling/logaling-command [master] not make Glossary#update raise exception when new note passed

Zurück zum Archiv-Index

null+****@clear***** null+****@clear*****
Sun Jan 15 10:53:13 JST 2012


KITAITI Makoto	2012-01-15 10:53:13 +0900 (Sun, 15 Jan 2012)

  New Revision: e1c14bf87320614806aa60c1985ab043016ff030

  Merged 8f8133b: Merge pull request #16 from KitaitiMakoto/improve-update-note-only

  Log:
    not make Glossary#update raise exception when new note passed

  Modified files:
    lib/logaling/glossary.rb

  Modified: lib/logaling/glossary.rb (+9 -2)
===================================================================
--- lib/logaling/glossary.rb    2012-01-15 10:06:23 +0900 (53898c8)
+++ lib/logaling/glossary.rb    2012-01-15 10:53:13 +0900 (795ecc7)
@@ -85,8 +85,11 @@ module Logaling
       raise GlossaryNotFound unless File.exist?(@path)
 
       glossary = Glossary.load_glossary(@path)
-      if bilingual_pair_exists?(glossary, source_term, new_target_term)
-        raise TermError, "term '#{source_term}: #{target_term}' already exists in '#{@glossary}'"
+      if bilingual_pair_exists_and_has_same_note?(glossary, source_term, new_target_term, note)
+        err_msg = "term '#{source_term}: #{target_term}"
+        err_msg << "(#{note})" unless note.empty?
+        err_msg << "' already exists in '#{@glossary}'"
+        raise TermError, err_msg
       end
 
       target_index = find_term_index(glossary, source_term, target_term)
@@ -156,6 +159,10 @@ module Logaling
       target_terms(glossary, source_term).any?{|data| data['target_term'] == target_term }
     end
 
+    def bilingual_pair_exists_and_has_same_note?(glossary, source_term, target_term, note)
+      target_terms(glossary, source_term).any?{|data| data['target_term'] == target_term && data['note'] == note}
+    end
+
     def target_terms(glossary, source_term)
       glossary.select {|term| term['source_term'] == source_term }
     end




More information about the logaling-commit mailing list
Zurück zum Archiv-Index