Kouhei Sutou
null+****@clear*****
Sat Jan 4 18:56:26 JST 2014
Kouhei Sutou 2014-01-04 18:56:26 +0900 (Sat, 04 Jan 2014) New Revision: d5cced835445853cc2d6f2d8ce8a0238155bcc8e https://github.com/ranguba/chupa-text/commit/d5cced835445853cc2d6f2d8ce8a0238155bcc8e Message: Add FileContent to use in Data Copied files: lib/chupa-text/file-content.rb (from lib/chupa-text.rb) test/test-file-content.rb (from lib/chupa-text.rb) Modified files: lib/chupa-text.rb Modified: lib/chupa-text.rb (+1 -0) =================================================================== --- lib/chupa-text.rb 2014-01-03 23:59:41 +0900 (78517b2) +++ lib/chupa-text.rb 2014-01-04 18:56:26 +0900 (2e37f56) @@ -27,4 +27,5 @@ require "chupa-text/formatters" require "chupa-text/mime-type" require "chupa-text/mime-type-registry" +require "chupa-text/file-content" require "chupa-text/command" Copied: lib/chupa-text/file-content.rb (+17 -12) 66% =================================================================== --- lib/chupa-text.rb 2014-01-03 23:59:41 +0900 (78517b2) +++ lib/chupa-text/file-content.rb 2014-01-04 18:56:26 +0900 (23274c1) @@ -14,17 +14,22 @@ # 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" +module ChupaText + class FileContent + attr_reader :size + attr_reader :path -require "chupa-text/configuration" -require "chupa-text/configuration-loader" -require "chupa-text/data" -require "chupa-text/decomposer" -require "chupa-text/decomposer-registry" -require "chupa-text/decomposers" -require "chupa-text/extractor" -require "chupa-text/formatters" -require "chupa-text/mime-type" -require "chupa-text/mime-type-registry" + def initialize(path) + @path = path + @size = File.size(@path) + end -require "chupa-text/command" + def open(&block) + File.open(@path, "rb", &block) + end + + def body + @body ||= open {|file| file.read} + end + end +end Copied: test/test-file-content.rb (+34 -12) 50% =================================================================== --- lib/chupa-text.rb 2014-01-03 23:59:41 +0900 (78517b2) +++ test/test-file-content.rb 2014-01-04 18:56:26 +0900 (d59b233) @@ -14,17 +14,39 @@ # 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" +class TestFileContent < Test::Unit::TestCase + def setup + @file = Tempfile.new(["test-file-content", ".txt"]) + end -require "chupa-text/configuration" -require "chupa-text/configuration-loader" -require "chupa-text/data" -require "chupa-text/decomposer" -require "chupa-text/decomposer-registry" -require "chupa-text/decomposers" -require "chupa-text/extractor" -require "chupa-text/formatters" -require "chupa-text/mime-type" -require "chupa-text/mime-type-registry" + def write(string) + @file.write(string) + @file.flush + end -require "chupa-text/command" + def test_size + body = "Hello" + write(body) + content = ChupaText::FileContent.new(@file.path) + assert_equal(body.bytesize, content.size) + end + + def test_path + content = ChupaText::FileContent.new(@file.path) + assert_equal(@file.path, content.path) + end + + def test_body + body = "Hello" + write(body) + content = ChupaText::FileContent.new(@file.path) + assert_equal(body, content.body) + end + + def test_open + body = "Hello" + write(body) + content = ChupaText::FileContent.new(@file.path) + assert_equal(body, content.open {|file| file.read}) + end +end -------------- next part -------------- HTML����������������������������... Download