This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 04a7b68  ARROW-4924: [Ruby] Add Decimal128#to_s(scale=nil)
04a7b68 is described below

commit 04a7b682dceb8de0f707a37b51e5411ada963cd8
Author: Yosuke Shiro <yosuke.shiro...@gmail.com>
AuthorDate: Sun Mar 17 05:36:27 2019 +0900

    ARROW-4924: [Ruby] Add Decimal128#to_s(scale=nil)
    
    Author: Yosuke Shiro <yosuke.shiro...@gmail.com>
    
    Closes #3936 from shiro615/ruby-decimal128-to-s and squashes the following 
commits:
    
    7d93da42 <Yosuke Shiro>  Add Decimal128#to_s(scale=nil)
---
 .../test-decimal128.rb => lib/arrow/decimal128.rb} | 50 +++++++++-------------
 ruby/red-arrow/lib/arrow/loader.rb                 |  1 +
 ruby/red-arrow/test/test-decimal128.rb             | 12 ++++++
 3 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/ruby/red-arrow/test/test-decimal128.rb 
b/ruby/red-arrow/lib/arrow/decimal128.rb
similarity index 55%
copy from ruby/red-arrow/test/test-decimal128.rb
copy to ruby/red-arrow/lib/arrow/decimal128.rb
index 82c6fe3..20da7e2 100644
--- a/ruby/red-arrow/test/test-decimal128.rb
+++ b/ruby/red-arrow/lib/arrow/decimal128.rb
@@ -15,37 +15,27 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class Decimal128Test < Test::Unit::TestCase
-  sub_test_case("instance methods") do
-    def setup
-      @decimal128 = Arrow::Decimal128.new("10.1")
-    end
-
-    sub_test_case("#==") do
-      test("Arrow::Decimal128") do
-        assert do
-          @decimal128 == @decimal128
-        end
-      end
-
-      test("not Arrow::Decimal128") do
-        assert do
-          not (@decimal128 == 10.1)
-        end
-      end
-    end
-
-    sub_test_case("#!=") do
-      test("Arrow::Decimal128") do
-        assert do
-          not (@decimal128 != @decimal128)
-        end
-      end
+module Arrow
+  class Decimal128
+    alias_method :to_s_raw, :to_s
 
-      test("not Arrow::Decimal128") do
-        assert do
-          @decimal128 != 10.1
-        end
+    # @overload to_s
+    #
+    #   @return [String]
+    #     The string representation of the decimal.
+    #
+    # @overload to_s(scale)
+    #
+    #   @param scale [Integer] The scale of the decimal.
+    #   @return [String]
+    #      The string representation of the decimal including the scale.
+    #
+    # @since 0.13.0
+    def to_s(scale=nil)
+      if scale
+        to_string_scale(scale)
+      else
+        to_s_raw
       end
     end
   end
diff --git a/ruby/red-arrow/lib/arrow/loader.rb 
b/ruby/red-arrow/lib/arrow/loader.rb
index 280229b..a4b3604 100644
--- a/ruby/red-arrow/lib/arrow/loader.rb
+++ b/ruby/red-arrow/lib/arrow/loader.rb
@@ -45,6 +45,7 @@ module Arrow
       require "arrow/date32-array-builder"
       require "arrow/date64-array"
       require "arrow/date64-array-builder"
+      require "arrow/decimal128"
       require "arrow/decimal128-array-builder"
       require "arrow/decimal128-data-type"
       require "arrow/dense-union-data-type"
diff --git a/ruby/red-arrow/test/test-decimal128.rb 
b/ruby/red-arrow/test/test-decimal128.rb
index 82c6fe3..1476bc3 100644
--- a/ruby/red-arrow/test/test-decimal128.rb
+++ b/ruby/red-arrow/test/test-decimal128.rb
@@ -48,5 +48,17 @@ class Decimal128Test < Test::Unit::TestCase
         end
       end
     end
+
+    sub_test_case("#to_s") do
+      test("default") do
+        assert_equal("101",
+                     @decimal128.to_s)
+      end
+
+      test("scale") do
+        assert_equal("10.1",
+                     @decimal128.to_s(1))
+      end
+    end
   end
 end

Reply via email to