module Seatbelt::TapeDeck::ClassMethods
Public Instance Methods
respond(question)
click to toggle source
Public: Detects an answer that matches the question and calls the translation block.
question - The question or query as String
# File lib/seatbelt/tape_deck.rb, line 57 def respond(question) found_answer = nil tapes.each do |tape| found_answer = get_answer_from_tape(tape, :question => question) break if found_answer end raise Seatbelt::Errors::NoTapeFoundForQueryError unless found_answer delegate_answer(found_answer, :question => question) if found_answer end
Also aliased as: answer
tapes()
click to toggle source
A store to hold tapes for the class that implements the module.
Returns store.
# File lib/seatbelt/tape_deck.rb, line 22 def tapes @tapes = [] if @tapes.nil? @tapes end
use_tape(tape_name)
click to toggle source
Public: Adds a tape to the tape store. If a passed tape is already included in the store, it will not included a second time.
tape_name - (class) name of the tape.
# File lib/seatbelt/tape_deck.rb, line 32 def use_tape(tape_name) unless tape_name.in?(tapes) unless tape_name.tape_deck.nil? raise Seatbelt::Errors::MultipleTapeUsageDetectedError end tape_name.tape_deck.nil? tape_name.tape_deck = Module.const_get(self.name) tapes << tape_name end end
Also aliased as: add_tape
use_tapes(*tapes)
click to toggle source
Public: Adds a bunch of tapes to the store. See use_tape
.
*tapes - A list of tapes.
# File lib/seatbelt/tape_deck.rb, line 48 def use_tapes(*tapes) tapes.flatten.each { |tape| self.use_tape(tape) } end