lib/gamefic/query/text.rb in gamefic-3.0.0 vs lib/gamefic/query/text.rb in gamefic-3.1.0

- old
+ new

@@ -3,16 +3,21 @@ module Gamefic module Query # A special query that handles text instead of entities. # class Text - # @param argument [String, Regexp, nil] - def initialize argument = nil + # @param argument [String, Regexp] + def initialize argument = /.*/ @argument = argument validate end + # @return [String, Regexp] + def select(_subject) + @argument + end + def query _subject, token if match? token Result.new(token, '') else Result.new(nil, token) @@ -21,24 +26,30 @@ def precision 0 end + def accept? _subject, argument + match? argument + end + + def ambiguous? + true + end + private def match? token - return true if @argument.nil? - case @argument when Regexp token =~ @argument else token == @argument end end def validate - return if @argument.nil? || @argument.is_a?(String) || @argument.is_a?(Regexp) + return if @argument.is_a?(String) || @argument.is_a?(Regexp) raise ArgumentError, 'Invalid text query argument' end end end