Module: Seatbelt::TapeDeck::ClassMethods
- Includes:
- Seatbelt::Tapes::Util::Delegate
- Defined in:
- lib/seatbelt/tape_deck.rb
Instance Method Summary collapse
-
#respond(question) ⇒ Object
(also: #answer)
Public: Detects an answer that matches the question and calls the translation block.
-
#tapes ⇒ Object
A store to hold tapes for the class that implements the module.
-
#use_tape(tape_name) ⇒ Object
(also: #add_tape)
Public: Adds a tape to the tape store.
-
#use_tapes(*tapes) ⇒ Object
Public: Adds a bunch of tapes to the store.
Methods included from Seatbelt::Tapes::Util::Delegate
#delegate_answer, #get_answer_from_tape
Instance Method Details
#respond(question) ⇒ Object Also known as: answer
Public: Detects an answer that matches the question and calls the translation block.
question - The question or query as String
58 59 60 61 62 63 64 65 66 |
# File 'lib/seatbelt/tape_deck.rb', line 58 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 |
#tapes ⇒ Object
A store to hold tapes for the class that implements the module.
Returns store.
23 24 25 26 |
# File 'lib/seatbelt/tape_deck.rb', line 23 def tapes @tapes = [] if @tapes.nil? @tapes end |
#use_tape(tape_name) ⇒ Object Also known as: add_tape
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.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/seatbelt/tape_deck.rb', line 33 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 |
#use_tapes(*tapes) ⇒ Object
Public: Adds a bunch of tapes to the store. See #use_tape.
*tapes - A list of tapes.
49 50 51 |
# File 'lib/seatbelt/tape_deck.rb', line 49 def use_tapes(*tapes) tapes.flatten.each { |tape| self.use_tape(tape) } end |