lib/gamefic/response.rb in gamefic-3.5.0 vs lib/gamefic/response.rb in gamefic-3.6.0

- old
+ new

@@ -75,25 +75,35 @@ # # @param actor [Actor] # @param expression [Expression] # @return [Command, nil] def to_command actor, expression - return nil unless expression.verb == verb && expression.tokens.length <= queries.length + return log_and_discard unless expression.verb == verb && expression.tokens.length <= queries.length results = filter(actor, expression) - return nil unless results + return log_and_discard unless results + Gamefic.logger.info "Accepted #{inspect}" Command.new( verb, results.map(&:match), results.sum(&:strictness), precision ) end + def inspect + "#<#{self.class} #{([verb] + queries).map(&:inspect).join(', ')}>" + end + private + def log_and_discard + Gamefic.logger.info "Discarded #{inspect}" + nil + end + def filter actor, expression remainder = '' result = queries.zip(expression.tokens) .map do |query, token| token = "#{remainder} #{token}".strip @@ -124,10 +134,10 @@ end end def select_query arg, narrative case arg - when Entity, Class, Module, Proc, Proxy + when Entity, Class, Module, Proc, Proxy, Proxy::Base narrative.available(arg) when String, Regexp narrative.plaintext(arg) when Query::Base, Query::Text arg