Kouhei Sutou
null+****@clear*****
Tue Dec 31 22:09:32 JST 2013
Kouhei Sutou 2013-12-31 22:09:32 +0900 (Tue, 31 Dec 2013) New Revision: 7421ea1a37118424dac45cf91883b6e2a4a3176e https://github.com/ranguba/chupa-text/commit/7421ea1a37118424dac45cf91883b6e2a4a3176e Message: Add minimum implementation Added files: lib/chupa-text.rb lib/chupa-text/data.rb lib/chupa-text/feeder.rb lib/chupa-text/version.rb test/run-test.rb test/test-data.rb test/test-feeder.rb Added: lib/chupa-text.rb (+19 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text.rb 2013-12-31 22:09:32 +0900 (4d43e44) @@ -0,0 +1,19 @@ +# 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 + +require "chupa-text/version" + +require "chupa-text/feeder" Added: lib/chupa-text/data.rb (+76 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text/data.rb 2013-12-31 22:09:32 +0900 (5fcc544) @@ -0,0 +1,76 @@ +# 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 + +require "pathname" + +module ChupaText + class Data + class << self + def open(path) + data = new + data.path = path + if block_given? + yield(data) + else + data + end + end + end + + attr_writer :body + attr_accessor :attributes + attr_reader :path + + def initialize + @body = nil + @attributes = {} + @path = nil + end + + def body + @body ||= read_body + end + + def path=(path) + path = Pathname(path) if path.is_a?(String) + @path = path + end + + def [](name) + @attributes[name] + end + + def []=(name, value) + @attributes[name] = value + end + + def content_type + self["content-type"] + end + + def content_type=(type) + self["content-type"] = type + end + + private + def read_body + return nil if****@path*****? + @path.open("rb") do |file| + file.read + end + end + end +end Added: lib/chupa-text/feeder.rb (+28 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text/feeder.rb 2013-12-31 22:09:32 +0900 (f0b6ebf) @@ -0,0 +1,28 @@ +# 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 + +require "chupa-text/data" + +module ChupaText + class Feeder + def feed(data) + extracted = Data.new + extracted.content_type = "text/plain" + extracted.body = data.body + yield(extracted) + end + end +end Added: lib/chupa-text/version.rb (+19 -0) 100644 =================================================================== --- /dev/null +++ lib/chupa-text/version.rb 2013-12-31 22:09:32 +0900 (6d9c1b6) @@ -0,0 +1,19 @@ +# 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 + VERSION = "1.0.0" +end Added: test/run-test.rb (+31 -0) 100755 =================================================================== --- /dev/null +++ test/run-test.rb 2013-12-31 22:09:32 +0900 (3699131) @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +# +# 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 + +$VERBOSE = true + +require "pathname" + +require "test-unit" + +base_dir = Pathname(__FILE__).dirname +lib_dir = base_dir + "lib" +$LOAD_PATH.unshift(lib_dir.to_s) + +require "chupa-text" + +exit(Test::Unit::AutoRunner.run(true)) Added: test/test-data.rb (+18 -0) 100644 =================================================================== --- /dev/null +++ test/test-data.rb 2013-12-31 22:09:32 +0900 (300be1a) @@ -0,0 +1,18 @@ +# 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 TestData < Test::Unit::TestCase +end Added: test/test-feeder.rb (+41 -0) 100644 =================================================================== --- /dev/null +++ test/test-feeder.rb 2013-12-31 22:09:32 +0900 (ccf01ff) @@ -0,0 +1,41 @@ +# 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 TestFeeder < Test::Unit::TestCase + def setup + @feeder = ChupaText::Feeder.new + end + + sub_test_case("feed") do + private + def feed(data) + texts = [] + @feeder.feed(data) do |extracted_data| + texts << extracted_data.body + end + texts + end + + sub_test_case("text") do + def test_text + data = ChupaText::Data.new + data.content_type = "text/plain" + data.body = "Hello" + assert_equal(["Hello"], feed(data)) + end + end + end +end -------------- next part -------------- HTML����������������������������... 다운로드