orochi
A ruby gem that helps ActiveRecord-ize directions and route data.
Note: this gem has only been tested in Rails 3
setup
sudo gem install orochi rake orochi:awaken
quick start
Orochi needs to know which models you intend to make routeable. So any model that has a start and stop destination can be represented as:
class YourModel < ActiveRecord::Base acts_as_routeable end
Orochi still isn’t quite smart enough to make the association on its own, so for the time being you will have to generate a migration:
rails generate migration add_router_id_to_your_model
add in the necessary columns:
class AddRouterIdToYourModel < ActiveRecord::Migration self.up add_column :your_models, :router_id, :integer, :references => :routers end self.down remove_column :your_models, :router_id end end
then run the migration:
db:migrate
Now you’re set up and ready to go!
usage
your_model_instance.set_endpoints!("start_address", "stop_address") your_model_instance.route!
Now you can do some of the following:
your_model_instance.polyline # Polyline representation for Google Maps your_model_instance.directions # List of directions your_model_instance.reverse # A creates a router with the reversed address + routes your_model_instance.includes?(point_of_interest) # Returns if point of interest is within your route