google_maps.rb
684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class GoogleMaps
  extend ActionView::Helpers::TagHelper
  class << self
    def erase_config
      @config = nil
    end
    def config_file
      File.join(RAILS_ROOT, 'config', 'web2.0.yml')
    end
    def config
      if @config.nil?
        if File.exists?(config_file)
          yaml = YAML.load_file(config_file)
          @config = yaml['googlemaps']
        end
      end
      @config ||= {}
    end
    def enabled?
      !config['key'].nil?
    end
    def key
      config['key'] || ''
    end
    def initial_zoom
      config['initial_zoom'] || 4
    end
    def api_url
      "http://maps.google.com/maps?file=api&v=2&key=#{key}"
    end
  end
end