rhyme 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/rhyme.rb +49 -0
  2. data/lib/rhyme/version.rb +11 -0
  3. metadata +4 -3
data/lib/rhyme.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "date"
2
+
3
+ module Rhyme
4
+
5
+ def self.translate(x)
6
+ case x.class.to_s
7
+ when "Java::JavaUtil::HashMap" then self.translate_hash_map(x)
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)
13
+ else x
14
+ end
15
+ end
16
+
17
+ def self.translate_hash_map(map)
18
+ hash = Hash.new
19
+ map.key_set.each { |key| hash[key] = translate(map.get(key)) }
20
+ return hash
21
+ end
22
+
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 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 x }
46
+ return array_list
47
+ end
48
+
49
+ end
@@ -0,0 +1,11 @@
1
+ module Rhyme
2
+
3
+ module VERSION #:nodoc:
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 2
7
+
8
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
+ end
10
+
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhyme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Carrion
@@ -31,8 +31,9 @@ extensions: []
31
31
 
32
32
  extra_rdoc_files: []
33
33
 
34
- files: []
35
-
34
+ files:
35
+ - lib/rhyme.rb
36
+ - lib/rhyme/version.rb
36
37
  has_rdoc: true
37
38
  homepage: http://rhyme.rubyforge.org
38
39
  post_install_message: ""