Class: Geogov::Mapit::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/geogov/providers/mapit.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, params = []) ⇒ Method

Returns a new instance of Method.



9
10
11
12
# File 'lib/geogov/providers/mapit.rb', line 9

def initialize(url, params = [])
  @url = url
  @params = params
end

Instance Method Details

#call(base_url) ⇒ Object



27
28
29
# File 'lib/geogov/providers/mapit.rb', line 27

def call(base_url)
  Geogov.get_json(self.to_url(base_url))
end

#to_url(base_url) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/geogov/providers/mapit.rb', line 14

def to_url(base_url)
  url = "/#{@url}" unless /^\//.match(@url)
  params = @params.map { |p|
    p = p.join(",") if p.is_a?(Array)
    # Messy, but MapIt gets upset if you escape commas
    CGI::escape(p).gsub('%2C', ',')
  }
  url_path = "#{base_url}#{url}"
  url_path += "/#{params.join("/")}" if params.length > 0
  url_path += ".json"
  return url_path
end