h1. orochi
-
A ruby gem that helps ActiveRecord-ize directions and route data.
-
Note: this gem has only been tested in Rails 3
h2. setup
pre. sudo gem install orochi rake orochi:awaken
h2. 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:
pre. 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:
pre. rails generate migration add_router_id_to_your_model
-
add in the necessary columns:
pre. 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:
pre. db:migrate
-
Now you're set up and ready to go!
h2. usage
pre. your_model_instance.set_endpoints!(“start_address”, “stop_address”) your_model_instance.route!
-
Now you can do some of the following:
pre. 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