[Groonga-commit] ranguba/chupa-text at 14cce61 [master] Use DecomposerRegistory

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 1 23:02:11 JST 2014


Kouhei Sutou	2014-01-01 23:02:11 +0900 (Wed, 01 Jan 2014)

  New Revision: 14cce61b6aa64a0a4f1ad2276524d2adcb7aac67
  https://github.com/ranguba/chupa-text/commit/14cce61b6aa64a0a4f1ad2276524d2adcb7aac67

  Message:
    Use DecomposerRegistory

  Modified files:
    lib/chupa-text/command/chupa-text.rb
    lib/chupa-text/decomposer.rb

  Modified: lib/chupa-text/command/chupa-text.rb (+12 -2)
===================================================================
--- lib/chupa-text/command/chupa-text.rb    2014-01-01 23:01:44 +0900 (8dc5caf)
+++ lib/chupa-text/command/chupa-text.rb    2014-01-01 23:02:11 +0900 (52fe6f4)
@@ -25,20 +25,30 @@ module ChupaText
       end
 
       def initialize
-        @feeder = Feeder.new
       end
 
       def run(*arguments)
         paths = arguments
+        feeder = create_feeder
         paths.each do |path|
           data = Data.new
           data.path = path
-          @feeder.feed(data) do |extracted|
+          feeder.feed(data) do |extracted|
             puts(extracted.body)
           end
         end
         true
       end
+
+      private
+      def create_feeder
+        Decomposer.load
+        feeder = Feeder.new
+        Decomposer.registory.decomposers.each do |decomposer|
+          feeder.add_decomposer(decomposer)
+        end
+        feeder
+      end
     end
   end
 end

  Modified: lib/chupa-text/decomposer.rb (+19 -0)
===================================================================
--- lib/chupa-text/decomposer.rb    2014-01-01 23:01:44 +0900 (ba73c6d)
+++ lib/chupa-text/decomposer.rb    2014-01-01 23:02:11 +0900 (9585eca)
@@ -14,8 +14,27 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "chupa-text/decomposer-registory"
+
 module ChupaText
   class Decomposer
+    class << self
+      def registory
+        @@registory ||= DecomposerRegistory.new
+      end
+
+      def load
+        $LOAD_PATH.each do |load_path|
+          next unless File.directory?(load_path)
+          Dir.chdir(load_path) do
+            Dir.glob("chupa-text/plugin/decomposer/*.rb") do |plugin_path|
+              require plugin_path.gsub(/\.rb\z/, "")
+            end
+          end
+        end
+      end
+    end
+
     def target?(data)
       false
     end
-------------- next part --------------
HTML����������������������������...
下載 



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