[logaling-commit] logaling/logaling-command [master] Add Project#glossaries

Zurück zum Archiv-Index

null+****@clear***** null+****@clear*****
Tue Jul 3 15:58:35 JST 2012


SUZUKI Miho	2012-07-03 15:58:35 +0900 (Tue, 03 Jul 2012)

  New Revision: b8bbac60a79209227e01c1483fb87755aaa5d2f8
  https://github.com/logaling/logaling-command/commit/b8bbac60a79209227e01c1483fb87755aaa5d2f8

  Merged b6be24a: Merge pull request #64 from logaling/add-glossaries-to-project

  Log:
    Add Project#glossaries

  Added files:
    spec/logaling/project_spec.rb
  Modified files:
    lib/logaling/project.rb

  Modified: lib/logaling/project.rb (+9 -0)
===================================================================
--- lib/logaling/project.rb    2012-06-29 15:04:25 +0900 (4356a6a)
+++ lib/logaling/project.rb    2012-07-03 15:58:35 +0900 (e7fe5a1)
@@ -45,6 +45,15 @@ module Logaling
       File.basename(@path)
     end
 
+    def glossaries
+      all_glossary_source_path = Dir.glob(File.join(glossary_source_path, "*"))
+      glossaries = all_glossary_source_path.map do |source_path|
+        name, source_language, target_language, type = File.basename(source_path).split(/\./)
+        find_glossary(source_language, target_language)
+      end
+      glossaries.uniq{|glossary| glossary.to_s }
+    end
+
     def find_glossary(source_language, target_language)
       Logaling::Glossary.new(name, source_language, target_language, self)
     end

  Added: spec/logaling/project_spec.rb (+67 -0) 100644
===================================================================
--- /dev/null
+++ spec/logaling/project_spec.rb    2012-07-03 15:58:35 +0900 (cba7e9a)
@@ -0,0 +1,67 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012  Miho SUZUKI
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
+require "fileutils"
+
+module Logaling
+  describe Project do
+    let(:logaling_home) { @logaling_home }
+    let(:repository) { Logaling::Repository.new(logaling_home) }
+    let(:project_path) { File.join(logaling_home, 'projects', 'spec') }
+    let(:project) { repository.find_project("spec") }
+
+    before do
+      FileUtils.remove_entry_secure(project_path, true)
+      FileUtils.mkdir_p(File.join(project_path, "glossary"))
+    end
+
+    describe "#glossaries" do
+      before do
+        FileUtils.touch(File.join(project_path, "glossary", "spec.en.ja.yml"))
+      end
+
+      context "project has only 'en-ja' glossary" do
+        it "should be include 'en-ja' glossary" do
+          project.glossaries.map(&:to_s).should be_include "spec.en.ja"
+        end
+      end
+
+      context "project has 'en-ja' 'fr-ja' glossaries" do
+        before do
+          FileUtils.touch(File.join(project_path, "glossary", "spec.fr.ja.yml"))
+        end
+
+        it "should be include 'en-ja' 'fr-ja' glossaries" do
+          %w(spec.en.ja spec.fr.ja).each do |glossary_name|
+            project.glossaries.map(&:to_s).should be_include glossary_name
+          end
+        end
+      end
+
+      context "project has two 'en-ja' glossary sources" do
+        before do
+          FileUtils.touch(File.join(project_path, "glossary", "spec.en.ja.csv"))
+        end
+
+        it "should count as one glossary" do
+          project.glossaries.size.should == 1
+        end
+      end
+    end
+  end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



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