SUZUKI Miho
null+****@clear*****
Mon Oct 29 11:15:53 JST 2012
SUZUKI Miho 2012-10-11 19:20:54 +0900 (Thu, 11 Oct 2012) New Revision: 7e628e1e0c68b9e48ed3a37a189ef0b1c37299e0 https://github.com/logaling/logaling-command/commit/7e628e1e0c68b9e48ed3a37a189ef0b1c37299e0 Merged fb2d86e: Merge pull request #85 from logaling/add-no-annotation-option Log: Add '--no-annotation' option Modified files: lib/logaling/command/application.rb lib/logaling/repository.rb spec/logaling/repository_spec.rb Modified: lib/logaling/command/application.rb (+2 -1) =================================================================== --- lib/logaling/command/application.rb 2012-09-28 14:43:03 +0900 (5d48523) +++ lib/logaling/command/application.rb 2012-10-11 19:20:54 +0900 (b9b8234) @@ -262,6 +262,7 @@ module Logaling::Command method_option "no-pager", type: :boolean, default: false method_option "no-color", type: :boolean, default: false method_option "dictionary", type: :boolean, default: false, aliases: "--dict" + method_option "no-annotation", type: :boolean, default: false def lookup(source_term) check_logaling_home_exists @repository.index @@ -272,7 +273,7 @@ module Logaling::Command else glossary = nil end - terms =****@repos*****(source_term, glossary, options["dictionary"]) + terms =****@repos*****(source_term, glossary, options["dictionary"], options["no-annotation"]) unless terms.empty? run_pager terms.each_with_index do |term, i| Modified: lib/logaling/repository.rb (+8 -1) =================================================================== --- lib/logaling/repository.rb 2012-09-28 14:43:03 +0900 (d39b8e9) +++ lib/logaling/repository.rb 2012-10-11 19:20:54 +0900 (9e4c789) @@ -82,7 +82,7 @@ module Logaling raise Logaling::CommandFailed, "Failed import_tmx #{glossary_source.class.name} to #{cache_path}." end - def lookup(source_term, glossary, dictionary=false) + def lookup(source_term, glossary, dictionary=false, no_annotation=false) raise Logaling::GlossaryDBNotFound unless File.exist?(logaling_db_home) terms = [] @@ -93,6 +93,13 @@ module Logaling terms = db.lookup(source_term, glossary) end end + no_annotation ? except_annotation(terms) : terms + end + + def except_annotation(terms) + Logaling::Glossary::SUPPORTED_ANNOTATION.map do |annotation| + terms.delete_if {|term| term[:note].index(annotation) } + end terms end Modified: spec/logaling/repository_spec.rb (+25 -0) =================================================================== --- spec/logaling/repository_spec.rb 2012-09-28 14:43:03 +0900 (5bdf15b) +++ spec/logaling/repository_spec.rb 2012-10-11 19:20:54 +0900 (0c3447a) @@ -89,6 +89,31 @@ module Logaling end end + context 'with no-annotation option' do + let(:annotation_word) { Logaling::Glossary::SUPPORTED_ANNOTATION.first } + before do + glossary.add("user", "ユーザ", "ユーザーではない") + glossary.add("user-logaling", "ユーザ", "ユーザーと迷い中 #{annotation_word}") + File.stub!(:mtime).and_return(Time.now - 1) + repository.index + @terms = repository.lookup("user", glossary, false, true) + @result = [{ + :glossary_name=>"spec", + :source_language=>"en", + :target_language=>"ja", + :source_term=>"user", + :snipped_source_term=>["", {:keyword=>"user"}], + :target_term=>"ユーザ", + :snipped_target_term=>["ユーザ"], + :note=>"ユーザーではない"}] + end + + it 'succeed at find by term without include annotation' do + @terms.should == @result + end + + end + context 'when tsv file as glossary exists' do let(:tsv_path) { glossary_source_path.sub(/yml$/, 'tsv') } -------------- next part -------------- An HTML attachment was scrubbed...Descargar