Class: Ipdb::Query
Instance Method Summary collapse
-
#each {|Query| ... } ⇒ XML
Parses the Locations from the Query.
-
#initialize(addr = nil, options = {}) ⇒ Query
constructor
Creates a new Query object.
-
#parse ⇒ Location
Process The Query Object And Return A Location Object.
-
#simple_map_image ⇒ String
Convenient Method to render the map url as an image in Rails.
-
#simple_map_url ⇒ String
Return a map url of addresses from the Query.
-
#to_json ⇒ Query
Return the Query object in json format.
-
#to_s ⇒ Query
(also: #to_xml)
Return the Query in XML format.
-
#url ⇒ String
Return the url of the Query.
Constructor Details
Instance Method Details
#each {|Query| ... } ⇒ XML
Parses the Locations from the Query.
60 61 62 63 64 |
# File 'lib/ipdb/query.rb', line 60 def each(&block) @xml.xpath('//Location').each do |location| block.call(Location.new(location, @timeout)) if block end end |
#parse ⇒ Location
Process The Query Object And Return A Location Object
44 45 46 |
# File 'lib/ipdb/query.rb', line 44 def parse Location.new(@xml.xpath('//Location'), @timeout) end |
#simple_map_image ⇒ String
Convenient Method to render the map url as an image in Rails.
118 119 120 |
# File 'lib/ipdb/query.rb', line 118 def simple_map_image "image_path(#{simple_map_url})" end |
#simple_map_url ⇒ String
Return a map url of addresses from the Query
103 104 105 106 107 108 109 110 111 |
# File 'lib/ipdb/query.rb', line 103 def simple_map_url @country_codes = [] @data = [] Enumerator.new(self,:each).to_a.collect {|x| @country_codes << x.country_code } @country_codes = @country_codes.uniq 1.upto(@country_codes.size) { |x| @data << '0' } url = "http://chart.apis.google.com/chart?cht=t&chs=440x220&chd=t:#{@data.join(',')}&chco=FFFFFF,4A4A4A,EBEBEB&chld=#{@country_codes}&chtm=world&chf=bg,s,EAF7FE" return url end |
#to_json ⇒ Query
Return the Query object in json format.
80 81 82 83 84 |
# File 'lib/ipdb/query.rb', line 80 def to_json json = "#{@url}&output=json" @doc = Nokogiri::HTML(open(json)) return @doc.xpath('//body/.').inner_text end |
#to_s ⇒ Query Also known as: to_xml
Return the Query in XML format.
91 92 93 |
# File 'lib/ipdb/query.rb', line 91 def to_s @xml end |
#url ⇒ String
Return the url of the Query
71 72 73 |
# File 'lib/ipdb/query.rb', line 71 def url @url end |