[logaling-commit] logaling/logaling-command [master] Use glossary object instead of glossary_info

Zurück zum Archiv-Index

null+****@clear***** null+****@clear*****
Fri Jun 22 19:18:59 JST 2012


SUZUKI Miho	2012-06-22 19:18:59 +0900 (Fri, 22 Jun 2012)

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

  Merged 7228757: Merge pull request #60 from logaling/refactor-structure

  Log:
    Use glossary object instead of glossary_info

  Modified files:
    lib/logaling/command/application.rb
    lib/logaling/external_glossaries/tmx.rb
    lib/logaling/external_glossary.rb
    lib/logaling/repository.rb

  Modified: lib/logaling/command/application.rb (+9 -18)
===================================================================
--- lib/logaling/command/application.rb    2012-06-19 21:31:15 +0900 (438b483)
+++ lib/logaling/command/application.rb    2012-06-22 19:18:59 +0900 (680aacb)
@@ -93,9 +93,13 @@ module Logaling::Command
       else
         case external_glossary
         when 'tmx'
-          glossary_info = initialize_import_parameter(args)
-          check_import_parameter(glossary_info)
-          @repository.import_tmx(Logaling::ExternalGlossary.get(external_glossary), glossary_info)
+          check_import_parameter(args)
+          url = args[1]
+          if url && !URI.parse(url).host
+            url = File::expand_path(url)
+          end
+          glossary = Logaling::Glossary.new(args[0], args[2], args[3])
+          @repository.import_tmx(Logaling::ExternalGlossary.get(external_glossary), glossary, url)
           @repository.index
         else
           @repository.import(Logaling::ExternalGlossary.get(external_glossary))
@@ -359,25 +363,12 @@ module Logaling::Command
       end
     end
 
-    def check_import_parameter(glossary_info)
-      unless glossary_info[:name] && glossary_info[:url]
+    def check_import_parameter(args)
+      unless args[0] && args[1]
         raise Logaling::CommandFailed, "Do 'loga import tmx <glossary name> <url or path>'"
       end
     end
 
-    def initialize_import_parameter(arr)
-      glossary_info = {}
-      url = arr[1]
-      if url && !URI.parse(url).host
-        url = File::expand_path(url)
-      end
-      glossary_info[:name] = arr[0]
-      glossary_info[:url] = url
-      glossary_info[:source_language] = arr[2]
-      glossary_info[:target_language] = arr[3]
-      glossary_info
-    end
-
     def register_and_index
       @repository.register(@dotfile_path, @config.glossary)
       @repository.index

  Modified: lib/logaling/external_glossaries/tmx.rb (+4 -4)
===================================================================
--- lib/logaling/external_glossaries/tmx.rb    2012-06-19 21:31:15 +0900 (f600194)
+++ lib/logaling/external_glossaries/tmx.rb    2012-06-22 19:18:59 +0900 (539efcb)
@@ -23,8 +23,8 @@ module Logaling
     output_format   'csv'
 
     private
-    def convert_to_csv(csv, glossary_info)
-      doc = ::Nokogiri::XML(open(glossary_info[:url], "r"))
+    def convert_to_csv(csv, glossary, url)
+      doc = ::Nokogiri::XML(open(url, "r"))
       tu_nodes = doc.xpath('//tmx/body/tu')
       tu_nodes.each do |tu|
         original = ""
@@ -33,12 +33,12 @@ module Logaling
         tu.children.each do |tuv|
           if tuv.name == "tuv"
             lang = convert_language_code_iso_639(tuv["lang"])
-            if lang == glossary_info[:source_language]
+            if lang == glossary.source_language
               tuv.children.each do |child|
                 original = child.text.strip if child.name == "seg"
                 notes << child.text.strip if child.name == "note"
               end
-            elsif lang == glossary_info[:target_language]
+            elsif lang == glossary.target_language
               tuv.children.each do |child|
                 translation = child.text.strip if child.name == "seg"
                 notes << child.text.strip if child.name == "note"

  Modified: lib/logaling/external_glossary.rb (+14 -14)
===================================================================
--- lib/logaling/external_glossary.rb    2012-06-19 21:31:15 +0900 (2e8e24a)
+++ lib/logaling/external_glossary.rb    2012-06-22 19:18:59 +0900 (3c87bae)
@@ -68,19 +68,19 @@ class Logaling::ExternalGlossary
     end
   end
 
-  def import(glossary_info=nil)
-    if glossary_info && glossary_info[:url]
-      unless file_exists?(glossary_info[:url])
-        raise Logaling::GlossaryNotFound, "Failed open url/path <#{glossary_info[:url]}>"
+  def import(glossary=nil, url=nil)
+    if glossary && url
+      unless file_exists?(url)
+        raise Logaling::GlossaryNotFound, "Failed open url/path <#{url}>"
       end
     end
-    File.open(import_file_name(glossary_info), "w") do |output|
+    File.open(import_file_name(glossary), "w") do |output|
       output_format = self.class.output_format
       output_format = output_format.to_s if output_format.is_a?(Symbol)
       case output_format
       when "csv"
-        if glossary_info
-          convert_to_csv(CSV.new(output), glossary_info)
+        if glossary
+          convert_to_csv(CSV.new(output), glossary, url)
         else
           convert_to_csv(CSV.new(output))
         end
@@ -91,14 +91,14 @@ class Logaling::ExternalGlossary
   end
 
   private
-  def import_file_name(glossary_info=nil)
-    if glossary_info
-      glossary_info[:name] ||= self.class.name
-      glossary_info[:source_language] ||= self.class.source_language
-      glossary_info[:target_language] ||= self.class.target_language
+  def import_file_name(glossary=nil)
+    if glossary
+      glossary.name ||= self.class.name
+      glossary.source_language ||= self.class.source_language
+      glossary.target_language ||= self.class.target_language
 
-      [glossary_info[:name], glossary_info[:source_language],
-       glossary_info[:target_language], self.class.output_format].join('.')
+      [glossary.name, glossary.source_language,
+       glossary.target_language, self.class.output_format].join('.')
     else
       [self.class.name, self.class.source_language,
        self.class.target_language, self.class.output_format].join('.')

  Modified: lib/logaling/repository.rb (+2 -2)
===================================================================
--- lib/logaling/repository.rb    2012-06-19 21:31:15 +0900 (aeec463)
+++ lib/logaling/repository.rb    2012-06-22 19:18:59 +0900 (2fa6b02)
@@ -53,10 +53,10 @@ module Logaling
       raise Logaling::CommandFailed, "Failed import #{glossary_source.class.name} to #{cache_path}."
     end
 
-    def import_tmx(glossary_source, glossary_info)
+    def import_tmx(glossary_source, glossary, url)
       FileUtils.mkdir_p(cache_path)
       Dir.chdir(cache_path) do
-        glossary_source.import(glossary_info)
+        glossary_source.import(glossary, url)
       end
     rescue Logaling::GlossaryNotFound => e
       raise e
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



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