Skip to content

Instantly share code, notes, and snippets.

@ariera
Created July 17, 2011 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariera/1087814 to your computer and use it in GitHub Desktop.
Save ariera/1087814 to your computer and use it in GitHub Desktop.
Codebrawl::James MLO

Intro

This James script asks the user for the origin and destination stations of the MLO network and reports to him how much time he has before his train passes by.

MLO stands for the Metro Ligero Oeste, the tramway network of the west Madrid area

I have to admit it is not specially useful since recognition of spanish names is not the strongest points of the Mac speech recognition (my metro stop is called Somosaguas Sur and it is barely impossible for James to recognize it). Maybe I could translate the names into english (actually that could be fun! somosaguas becomes wearewaters XDDD)

Usage

Only for Mac OS X you need macruby to make it work. Easiest way is with rvm:

rvm install macruby

Then make sure you are using it and install the james gem

rvm use macruby
gem install james
gem install diMLOrb
# MLO stands for the Metro Ligero Oeste, the tramway network for the west area of Madrid
# DiMLOrb (https://github.com/ariera/diMLOrb) is a gem to estimate conmutation times in the tramway network
# This James script asks the user for the origin and destination stations and informs him
# how much time he has before his train passes by.
require 'DiMLOrb'
James.dialog do
hear 'metro' => :metro
#Listen for each origin station in the MLO network
state :metro do
DiMLOrb::STATIONS.keys.each do |station|
hear station.to_s => "from_#{station}".to_sym
end
into {'from?'}
end
#define one state for each origin station and listen to the destination station
DiMLOrb::STATIONS.keys.each do |station|
state "from_#{station}".to_sym do
DiMLOrb::STATIONS.keys.each do |st|
hear st.to_s => "to_#{st}".to_sym
end
into {@origin = station; "from #{station}, to?"}
end
end
#define one state for each destination station and calculate the time
DiMLOrb::STATIONS.keys.each do |station|
state "to_#{station.to_s}".to_sym do
hear 'again'
into do
@destination = station
d = DiMLOrb::DiMLOrb.new(@origin, @destination)
"Next train from #{@origin} to #{@destination} is in #{d.proximo} minutes and then in #{d.siguiente} minutes, Sir."
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment