Skip to content

Instantly share code, notes, and snippets.

@dmclark
Created October 26, 2010 17:46
Show Gist options
  • Select an option

  • Save dmclark/647400 to your computer and use it in GitHub Desktop.

Select an option

Save dmclark/647400 to your computer and use it in GitHub Desktop.
class Route < ActiveRecord::Base
attr_accessor :startpaint_id, :endpaint_id, :directions
belongs_to :start, :class_name => "Venue", :foreign_key => "startpoint_id"
belongs_to :end, :class_name => "Venue", :foreign_key => "endpoint_id"
validates :startpoint_id, :presence => true
validates :endpoint_id, :presence => true
after_create :get_xml
def directions
self.doc.xpath('//step').map do |i|
{'description' => i.xpath('html_instructions').text.html_safe,
'distance' => i.xpath('distance/text').text.html_safe
}
end
end
private
def xml
GoogleDirections.new(self.start.location,self.end.location).xml
end
def doc(args)
Nokogiri::XML(self.xml)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment