Module: EnrichmentDb::Helper

Defined in:
lib/enrichment_db/helper.rb

Class Method Summary collapse

Class Method Details

.float_str_to_float(str) ⇒ Object

[View source]

4
5
6
7
8
9
10
11
# File 'lib/enrichment_db/helper.rb', line 4

def self.float_str_to_float(str)
   return if str.nil?
	if str.match(/^[0-9\.-]*$/)
		str.to_f
	else
		str
	end
end

.format_geo_result(result) ⇒ Object

[View source]

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/enrichment_db/helper.rb', line 19

def self.format_geo_result(result)
  if result.size == 1 
    puts "Found object"
    result = result.first
	  id = result['region_id']
    result = EnrichmentDb::Helper.hash_float_str_to_float(result)
    region_type = result['region_type']
    region_type = region_type[0..-2]
    region = EnrichmentDb::Geo.const_get(region_type).by_id(id.to_i)
    return if region.nil?

    region = EnrichmentDb::Helper.hash_float_str_to_float(region)
    result['region'] = region
    result
  elsif result.size > 1
    puts "More than 1 object found. Only wanted 1 object."
  else 
    puts "Nothing found"
  end
end

.hash_float_str_to_float(hash) ⇒ Object

[View source]

13
14
15
16
17
# File 'lib/enrichment_db/helper.rb', line 13

def self.hash_float_str_to_float(hash)
	hash.each_with_object({}) do |(k, v), h|
		h[k] = float_str_to_float(v)
	end
end