Kouhei Sutou
null+****@clear*****
Wed Jan 1 23:01:44 JST 2014
Kouhei Sutou 2014-01-01 23:01:44 +0900 (Wed, 01 Jan 2014) New Revision: 9612572806e4af8faed3f5e97f2b2c0aee87d5e3 https://github.com/ranguba/chupa-text/commit/9612572806e4af8faed3f5e97f2b2c0aee87d5e3 Message: Add DecomposerRegistory Added files: lib/chupa-text/decomposer-registory.rb test/test-decomposer-registory.rb Added: lib/chupa-text/decomposer-registory.rb (+39 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text/decomposer-registory.rb 2014-01-01 23:01:44 +0900 (03f8a2f) @@ -0,0 +1,39 @@ +# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +module ChupaText + class DecomposerRegistory + include Enumerable + + def initialize + @decomposer_classes = [] + end + + def register(decomposer_class) + @decomposer_classes << decomposer_class + end + + def each(&block) + @decomposer_classes.each(&block) + end + + def decomposers + collect do |decomposer_class| + decomposer_class.new + end + end + end +end Added: test/test-decomposer-registory.rb (+35 -0) 100644 =================================================================== --- /dev/null +++ test/test-decomposer-registory.rb 2014-01-01 23:01:44 +0900 (8b9c5f3) @@ -0,0 +1,35 @@ +# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +class TestDecomposerRegistory < Test::Unit::TestCase + class CSVDecomposer < ChupaText::Decomposer + end + + def setup + @registory = ChupaText::DecomposerRegistory.new + end + + def test_register + assert_equal([], @registory.to_a) + @registory.register(CSVDecomposer) + assert_equal([CSVDecomposer], @registory.to_a) + end + + def test_decomposers + @registory.register(CSVDecomposer) + assert_equal([CSVDecomposer], @registory.decomposers.collect(&:class)) + end +end -------------- next part -------------- HTML����������������������������...Download