Class: Google::Geo::Params

Inherits:
Hash
  • Object
show all
Defined in:
lib/google/geo/params.rb

Instance Method Summary collapse

Constructor Details

#initialize(geo, *args) ⇒ Params

Returns a new instance of Params.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/google/geo/params.rb', line 4

def initialize(geo, *args)
  @geo = geo
  
  params = { :key => @geo.key, :output => "xml", :hl => @geo.language, :oe => "utf-8" }
  
  query = case args.size
  when 1
    case args
    when String then args
    when Array  then args.join(",")
    end
  when 2
    args.join(",")
  else
    raise ArgumentError, "dunno what to do with #{args.inspect}"
  end
  
  params[:q] = query
  
  replace params
end

Instance Method Details

#extract_dimensions!Object



33
34
35
36
37
38
39
40
41
# File 'lib/google/geo/params.rb', line 33

def extract_dimensions!
  if size = delete(:size)
    size.split("x")
  elsif self[:width] and self[:height]
    [delete(:width), delete(:height)]
  else
    [500, 300]
  end
end

#to_uriObject



26
27
28
29
30
31
# File 'lib/google/geo/params.rb', line 26

def to_uri
  uri = "http://maps.google.com/maps/geo?" <<
    map { |k,v| "#{k}=#{URI.escape v.to_s}" }.join("&")
  # puts uri
  uri
end