dcrec1-rhyme 0.0.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,20 +4,46 @@ module Rhyme
4
4
 
5
5
  def self.translate(x)
6
6
  case x.class.to_s
7
- when "Java::JavaUtil::HashMap" then self.translate_map(x)
7
+ when "Java::JavaUtil::HashMap" then self.translate_hash_map(x)
8
8
  when "Java::JavaUtil::Date" then self.translate_date(x)
9
+ when "Java::JavaUtil::ArrayList" then self.translate_array_list(x)
10
+ when "Hash" then self.translate_hash(x)
11
+ when "Date" then self.translate_date(x)
12
+ when "Array" then self.translate_array(x)
9
13
  else x
10
14
  end
11
15
  end
12
16
 
13
- def self.translate_map(map)
17
+ def self.translate_hash_map(map)
14
18
  hash = Hash.new
15
19
  map.key_set.each { |key| hash[key] = translate(map.get(key)) }
16
20
  return hash
17
21
  end
18
22
 
19
- def self.translate_date(javaDate)
20
- Date.parse(Time.at(javaDate.getTime).strftime('%Y/%m/%d'))
23
+ def self.translate_date(date)
24
+ if date.class.to_s.eql? "Date"
25
+ java.util.Date.new(Time.local(date.strftime("%Y"), date.strftime("%m"), date.strftime("%d")).to_i * 1000)
26
+ else
27
+ Date.parse(Time.at(date.getTime / 1000).strftime('%Y/%m/%d'))
28
+ end
29
+ end
30
+
31
+ def self.translate_array_list(array_list)
32
+ array = Array.new
33
+ array_list.each { |x| array.push translate(x) }
34
+ return array
35
+ end
36
+
37
+ def self.translate_hash(hash)
38
+ map = java.util.HashMap.new
39
+ hash.each { |x| map.put x[0], translate(x[1]) }
40
+ return map
41
+ end
42
+
43
+ def self.translate_array(array)
44
+ array_list = java.util.ArrayList.new
45
+ array.each { |x| array_list.add translate(x) }
46
+ return array_list
21
47
  end
22
48
 
23
49
  end
@@ -2,8 +2,8 @@ module Rhyme
2
2
 
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 0
6
- TINY = 1
5
+ MINOR = 1
6
+ TINY = 3
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
@@ -9,17 +9,60 @@ describe Rhyme do
9
9
  Rhyme.translate(java.util.HashMap.new).class.should eql(Hash.new.class)
10
10
  end
11
11
 
12
+ it "should translate a Hash" do
13
+ Rhyme.translate(Hash.new).class.should eql(java.util.HashMap.new.class)
14
+ end
15
+
12
16
  it "should translates map values" do
13
17
  jmap = java.util.HashMap.new
14
18
  jmap.put "key1", "value"
15
19
  jmap.put "key2", java.util.Date.new(1234567890)
16
20
  rmap = Rhyme.translate(jmap)
17
21
  rmap["key1"].should eql("value")
18
- rmap["key2"].to_s.should eql("2009-02-13")
22
+ rmap["key2"].to_s.should eql("1970-01-15")
23
+ end
24
+
25
+ it "should translates hash values" do
26
+ rmap = Hash.new
27
+ rmap["key1"] = "value"
28
+ rmap["key2"] = Date.new(2009, 2, 13)
29
+ jmap = Rhyme.translate(rmap)
30
+ jmap.get("key1").should eql("value")
31
+ jmap.get("key2").to_string.should eql("Fri Feb 13 00:00:00 BRST 2009")
32
+ end
33
+
34
+ it "should translate a Java Date value" do
35
+ Rhyme.translate(java.util.Date.new(1234567890)).to_s.should eql("1970-01-15")
36
+ end
37
+
38
+ it "should translate a Java Date" do
39
+ Rhyme.translate(java.util.Date.new(1234567890)).class.should eql(Date.new.class)
40
+ end
41
+
42
+ it "should translate a Ruby Date value" do
43
+ Rhyme.translate(Date.new(2009, 2, 13)).to_s.should eql("Fri Feb 13 00:00:00 BRST 2009")
44
+ end
45
+
46
+ it "should translate a Ruby Date" do
47
+ Rhyme.translate(Date.new(2009, 2, 13)).class.should eql(java.util.Date.new(1234567890).class)
48
+ end
49
+
50
+ it "should translate an ArrayList" do
51
+ Rhyme.translate(java.util.ArrayList.new).class.should eql(Array.new.class)
52
+ end
53
+
54
+ it "should translate an ArrayList values" do
55
+ array = java.util.ArrayList.new
56
+ array.add java.util.HashMap.new
57
+ Rhyme.translate(array)[0].class.should eql(Hash.new.class)
58
+ end
59
+
60
+ it "should translate an Array" do
61
+ Rhyme.translate(Array.new).class.should eql(java.util.ArrayList.new.class)
19
62
  end
20
63
 
21
- it "should translate a Date" do
22
- Rhyme.translate(java.util.Date.new(1234567890)).to_s.should eql("2009-02-13")
64
+ it "should translate an Array values" do
65
+ Rhyme.translate([{}])[0].class.should eql(java.util.HashMap.new.class)
23
66
  end
24
67
 
25
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcrec1-rhyme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Carrion
@@ -20,18 +20,18 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.txt
23
+ - README.textile
24
24
  files:
25
25
  - lib/rhyme.rb
26
26
  - lib/rhyme/version.rb
27
- - README.txt
28
- has_rdoc: true
27
+ - README.textile
28
+ has_rdoc: false
29
29
  homepage: http://www.mouseoverstudio.com/blog/
30
30
  post_install_message:
31
31
  rdoc_options: []
32
32
 
33
33
  require_paths:
34
- - lib
34
+ - lib/
35
35
  required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
data/README.txt DELETED
@@ -1,51 +0,0 @@
1
- = rhyme
2
-
3
- * FIX (url)
4
-
5
- == DESCRIPTION:
6
-
7
- FIX (describe your package)
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- * FIX (list of features or problems)
12
-
13
- == SYNOPSIS:
14
-
15
- require "java"
16
- map = java.util.HashMap.new
17
- ... (populate map) ...
18
- hash = Rhyme.translate(map)
19
-
20
- == REQUIREMENTS:
21
-
22
- jruby
23
-
24
- == INSTALL:
25
-
26
- sudo gem install
27
-
28
- == LICENSE:
29
-
30
- (The MIT License)
31
-
32
- Copyright (c) 2008 Rhyme
33
-
34
- Permission is hereby granted, free of charge, to any person obtaining
35
- a copy of this software and associated documentation files (the
36
- 'Software'), to deal in the Software without restriction, including
37
- without limitation the rights to use, copy, modify, merge, publish,
38
- distribute, sublicense, and/or sell copies of the Software, and to
39
- permit persons to whom the Software is furnished to do so, subject to
40
- the following conditions:
41
-
42
- The above copyright notice and this permission notice shall be
43
- included in all copies or substantial portions of the Software.
44
-
45
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.