Class: IVES::Venue
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- IVES::Venue
- Defined in:
- lib/ives.rb
Class Method Summary collapse
-
.find(terms = {}) ⇒ Object
venue_name Name of venue address Address of venue (will be matched against both address fields) town Town postal_code Postcode/Zipcode.
- .find_by_postcode(postcode) ⇒ Object
- .get(id) ⇒ Object
- .search(name) ⇒ Object
Class Method Details
.find(terms = {}) ⇒ Object
venue_name Name of venue address Address of venue (will be matched against both address fields) town Town postal_code Postcode/Zipcode
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ives.rb', line 28 def self.find terms={} request = HTTPI::Request.new request.url = "http://www.ives.info/search" request.body = terms.collect{|k,v| "#{k}=#{v}"}.join("&") result = HTTPI.post request doc = Nokogiri::HTML(result.body) top = doc.css("ul.searchResults li a").first.attributes["href"] rescue nil if top Venue.get(top) else nil end end |
.find_by_postcode(postcode) ⇒ Object
46 47 48 |
# File 'lib/ives.rb', line 46 def self.find_by_postcode postcode find(:postal_code=>postcode) end |
.get(id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ives.rb', line 8 def self.get id full_id = id.to_s unless id.to_s =~ /ives\.info/ full_id = "http://ives.info/gb/#{id}" end doc = Nokogiri::XML(open("#{full_id}?format=xml")) do |config| config. = Nokogiri::XML::ParseOptions::NOBLANKS end attributes = {} doc.at("venue").children.each do |node| attributes[node.name] = node.children.to_s end attributes["id"] = id self.new(attributes) end |
.search(name) ⇒ Object
42 43 44 |
# File 'lib/ives.rb', line 42 def self.search name find(:venue_name=>name) end |