Module: Gamefic::Scriptable::Responses
- Included in:
- Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/responses.rb
Instance Method Summary collapse
-
#meta(verb, *args) {|| ... } ⇒ Response
Create a meta response to a command.
-
#respond(verb, *args) {|| ... } ⇒ Response
Create a response to a command.
- #responses ⇒ Array<Response>
- #responses_for(*verbs) ⇒ Array<Response>
- #verbs ⇒ Array<Symbol>
Methods included from Syntaxes
Methods included from Queries
#available, #children, #descendants, #extended, #global, #integer, #myself, #parent, #plaintext, #siblings
Instance Method Details
#meta(verb, *args) {|| ... } ⇒ Response
Create a meta response to a command.
46 47 48 49 50 51 |
# File 'lib/gamefic/scriptable/responses.rb', line 46 def verb, *args, &proc response = Response.new(verb&.to_sym, *args, meta: true, &proc) responses.push response syntaxes.push response.syntax response end |
#respond(verb, *args) {|| ... } ⇒ Response
Create a response to a command. A Response uses the ‘verb` argument to identify the imperative verb that triggers the action. It can also accept queries to tokenize the remainder of the input and filter for particular entities or properties. The `block“ argument is the proc to execute when the input matches all of the Response’s criteria (i.e., verb and queries).
32 33 34 35 36 37 |
# File 'lib/gamefic/scriptable/responses.rb', line 32 def respond verb, *args, &proc response = Response.new(verb&.to_sym, *args, &proc) responses.push response syntaxes.push response.syntax response end |
#responses ⇒ Array<Response>
54 55 56 |
# File 'lib/gamefic/scriptable/responses.rb', line 54 def responses @responses ||= [] end |
#responses_for(*verbs) ⇒ Array<Response>
59 60 61 62 |
# File 'lib/gamefic/scriptable/responses.rb', line 59 def responses_for(*verbs) symbols = verbs.map { |verb| verb&.to_sym } responses.select { |response| symbols.include? response.verb } end |
#verbs ⇒ Array<Symbol>
65 66 67 |
# File 'lib/gamefic/scriptable/responses.rb', line 65 def verbs responses.select(&:verb).uniq(&:verb) end |