Module: Geomash

Defined in:
lib/geomash/autoexpire_cache_dalli.rb,
lib/geomash.rb,
lib/geomash/tgn.rb,
lib/geomash/parser.rb,
lib/geomash/version.rb,
lib/geomash/geonames.rb,
lib/geomash/constants.rb,
lib/geomash/town_lookup.rb,
lib/geomash/standardizer.rb,
lib/geomash/autoexpire_cache_redis.rb

Overview

Defined Under Namespace

Classes: AutoexpireCacheDalli, AutoexpireCacheRedis, Constants, Geonames, Parser, Standardizer, TGN, TownLookup

Constant Summary collapse

VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.app_rootObject


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

def self.app_root
  return @app_root if @app_root
  @app_root = Rails.root if defined?(Rails) and defined?(Rails.root)
  @app_root ||= APP_ROOT if defined?(APP_ROOT)
  @app_root ||= '.'
end

.configObject


19
20
21
22
# File 'lib/geomash.rb', line 19

def self.config
  @config ||= YAML::load(File.open(config_path))[env]
    .with_indifferent_access
end

.config_pathObject


39
40
41
# File 'lib/geomash.rb', line 39

def self.config_path
  File.join(app_root, 'config', 'geomash.yml')
end

.envObject


31
32
33
34
35
36
37
# File 'lib/geomash.rb', line 31

def self.env
  return @env if @env
  #The following commented line always returns "test" in a rails c production console. Unsure of how to fix this yet...
  #@env = ENV["RAILS_ENV"] = "test" if ENV
  @env ||= Rails.env if defined?(Rails) and defined?(Rails.root)
  @env ||= 'development'
end

.parse(term, parse_term = false) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/geomash.rb', line 43

def self.parse(term,parse_term=false)
  return {} if term.blank?

  return_hash = Geomash::Parser.parse_mapquest_api(term, parse_term)

  if return_hash.blank?
    return_hash = Geomash::Parser.parse_bing_api(term, parse_term)
  end

  if return_hash.blank?
    return_hash = Geomash::Parser.parse_google_api(term, parse_term)
  end

  if return_hash[:country_part].present?
    #FIXME
    return_hash[:tgn] = Geomash::TGN.tgn_id_from_geo_hash(return_hash)

    if return_hash[:tgn].blank? || (return_hash[:tgn][:original_string_differs] && return_hash[:state_part].present?)
      geo_hash_temp =  Geomash::Standardizer.try_with_entered_names(return_hash)
      geo_hash_temp[:tgn] = Geomash::TGN.tgn_id_from_geo_hash(geo_hash_temp)  if geo_hash_temp.present?
      if geo_hash_temp.present? && return_hash[:tgn].blank?
        return_hash[:tgn] = geo_hash_temp[:tgn]
      elsif geo_hash_temp.present? && geo_hash_temp[:tgn][:parse_depth] > return_hash[:tgn][:parse_depth]
        return_hash[:tgn] = geo_hash_temp[:tgn]
      end

    end

    return_hash[:geonames] = Geomash::Geonames.geonames_id_from_geo_hash(return_hash)
  end

  return return_hash

end