[Groonga-commit] ranguba/chupa-text at 1053f9e [master] Add Data#extension

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 1 21:25:10 JST 2014


Kouhei Sutou	2014-01-01 21:25:10 +0900 (Wed, 01 Jan 2014)

  New Revision: 1053f9e5cd5ccd405f0d61ed369cb59eb650ceec
  https://github.com/ranguba/chupa-text/commit/1053f9e5cd5ccd405f0d61ed369cb59eb650ceec

  Message:
    Add Data#extension

  Modified files:
    lib/chupa-text/data.rb
    test/test-data.rb

  Modified: lib/chupa-text/data.rb (+8 -0)
===================================================================
--- lib/chupa-text/data.rb    2013-12-31 23:13:31 +0900 (38e4654)
+++ lib/chupa-text/data.rb    2014-01-01 21:25:10 +0900 (748c0db)
@@ -53,6 +53,14 @@ module ChupaText
       self["content-type"] = type
     end
 
+    # @return [String, nil] Normalized extension as String if {#path}
+    #   is not `nil`, `nil` otherwise. The normalized extension uses
+    #   lower case like `.pdf` not `.PDF`.
+    def extension
+      return nil if****@path*****?
+      @path.extname.downcase
+    end
+
     # @return [Bool] true if content-type is "text/plain", false
     #   otherwise.
     def text?

  Modified: test/test-data.rb (+24 -0)
===================================================================
--- test/test-data.rb    2013-12-31 23:13:31 +0900 (d409d83)
+++ test/test-data.rb    2014-01-01 21:25:10 +0900 (9aa09c8)
@@ -34,4 +34,28 @@ class TestData < Test::Unit::TestCase
       end
     end
   end
+
+  sub_test_case("extension") do
+    def test_no_path
+      assert_nil(extension(nil))
+    end
+
+    def test_lower_case
+      assert_equal(".md", extension("README.md"))
+    end
+
+    def test_upper_case
+      assert_equal(".md", extension("README.MD"))
+    end
+
+    def test_mixed_case
+      assert_equal(".md", extension("README.mD"))
+    end
+
+    private
+    def extension(path)
+      @data.path = path
+      @data.extension
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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