Module: Rhyme

Defined in:
lib/rhyme.rb,
lib/rhyme/version.rb

Defined Under Namespace

Modules: VERSION

Class Method Summary collapse

Class Method Details

.translate(x) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rhyme.rb', line 5

def self.translate(x)
  case x.class.to_s
    when "Java::JavaUtil::HashMap" then self.translate_hash_map(x)
    when "Java::JavaUtil::Date" then self.translate_date(x)
    when "Java::JavaUtil::ArrayList" then self.translate_array_list(x)
    when "Hash" then self.translate_hash(x)
    when "Date" then self.translate_date(x)
    when "Array" then self.translate_array(x)
    else x
  end
end

.translate_array(array) ⇒ Object



43
44
45
46
47
# File 'lib/rhyme.rb', line 43

def self.translate_array(array)
  array_list = java.util.ArrayList.new
  array.each { |x| array_list.add translate(x) }
  return array_list
end

.translate_array_list(array_list) ⇒ Object



31
32
33
34
35
# File 'lib/rhyme.rb', line 31

def self.translate_array_list(array_list)
	array = Array.new
	array_list.each { |x| array.push translate(x) }
	return array
end

.translate_date(date) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rhyme.rb', line 23

def self.translate_date(date)
  if date.class.to_s.eql? "Date"
    java.util.Date.new(Time.local(date.strftime("%Y"), date.strftime("%m"), date.strftime("%d")).to_i * 1000)
  else
    Date.parse(Time.at(date.getTime / 1000).strftime('%Y/%m/%d'))
  end
end

.translate_hash(hash) ⇒ Object



37
38
39
40
41
# File 'lib/rhyme.rb', line 37

def self.translate_hash(hash)
  map = java.util.HashMap.new
  hash.each { |x| map.put x[0], translate(x[1]) }
  return map
end

.translate_hash_map(map) ⇒ Object



17
18
19
20
21
# File 'lib/rhyme.rb', line 17

def self.translate_hash_map(map)
  hash = Hash.new
  map.key_set.each { |key| hash[key] = translate(map.get(key)) }
  return hash
end