zweikopf 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ java_import "clojure.lang.IPersistentMap"
2
2
  java_import "clojure.lang.IPersistentVector"
3
3
  java_import "clojure.lang.IPersistentList"
4
4
  java_import "clojure.lang.Keyword"
5
+ java_import "clojure.lang.Ratio"
5
6
 
6
7
  module Zweikopf
7
8
  module Transformer
@@ -19,6 +20,10 @@ module Zweikopf
19
20
  Array.from_ruby(obj, &block)
20
21
  elsif obj.is_a?(::Symbol)
21
22
  Keyword.from_ruby(obj)
23
+ elsif obj.is_a?(BigDecimal)
24
+ java.math.BigDecimal.new(obj.to_s)
25
+ elsif obj.is_a?(Rational)
26
+ Ratio.new(obj.numerator, obj.denominator)
22
27
  elsif !block.nil?
23
28
  from_ruby(yield(obj))
24
29
  else
@@ -35,6 +40,10 @@ module Zweikopf
35
40
  Array.from_clj(obj, &block)
36
41
  elsif obj.is_a?(::Keyword)
37
42
  Keyword.from_clj(obj)
43
+ elsif obj.is_a?(Java::java.math.BigDecimal)
44
+ BigDecimal.new(obj.to_s, obj.precision)
45
+ elsif obj.is_a?(Ratio)
46
+ Rational(obj.numerator, obj.denominator)
38
47
  elsif !block.nil?
39
48
  from_clj(yield(obj))
40
49
  else
@@ -1,3 +1,3 @@
1
1
  module Zweikopf
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/project.clj CHANGED
@@ -1,4 +1,4 @@
1
- (defproject zweikopf "1.0.0-SNAPSHOT"
1
+ (defproject zweikopf "1.0.0"
2
2
  :description "jruby clojure interop"
3
3
  :dependencies [[org.clojure/clojure "1.4.0"]
4
4
  [org.jruby/jruby-complete "1.7.1"]]
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'bigdecimal'
2
3
  java_import 'clojure.lang.Util'
3
4
 
4
5
  describe Zweikopf do
@@ -19,6 +20,18 @@ describe Zweikopf do
19
20
  end
20
21
  end
21
22
 
23
+ context "given a java.math.BigDecimal" do
24
+ it "creates a ruby BigDecimal" do
25
+ Zweikopf::Transformer.from_clj(java.math.BigDecimal.new("12.34")).should eql BigDecimal.new("12.34", 4)
26
+ end
27
+ end
28
+
29
+ context "given a clojure.lang.Ratio" do
30
+ it "creates a ruby Rational" do
31
+ Zweikopf::Transformer.from_clj(Java::clojure.lang.Ratio.new(1,3)).should eql Rational(1,3)
32
+ end
33
+ end
34
+
22
35
  context "when given a recursive hash structure" do
23
36
 
24
37
  #
@@ -10,6 +10,18 @@ describe Zweikopf do
10
10
  end
11
11
  end
12
12
 
13
+ context "when given a ruby BigDecimal" do
14
+ it "creates a java.math.Bigdecimal" do
15
+ Zweikopf::Transformer.from_ruby(BigDecimal.new('12.34', 4)).should eql java.math.BigDecimal.new('12.34')
16
+ end
17
+ end
18
+
19
+ context "when given a ruby Rational" do
20
+ it "creates a clojure.lang.Ratio" do
21
+ Zweikopf::Transformer.from_ruby(Rational(1,3)).should eql Java::clojure.lang.Ratio.new(1,3)
22
+ end
23
+ end
24
+
13
25
  context "when given a non-recursive hash structure" do
14
26
 
15
27
  #
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zweikopf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Oleksandr Petrov
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2014-01-27 00:00:00 Z
13
+ date: 2014-01-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake