class Gamefic::Query::Text

A special query that handles text instead of entities.

Public Class Methods

new(argument = /.*/, name: self.class.name) click to toggle source

@param argument [String, Regexp] @param name [String, nil]

Calls superclass method Gamefic::Query::Base::new
# File lib/gamefic/query/text.rb, line 10
def initialize argument = /.*/, name: self.class.name
  super(argument, name: name)
  validate_argument
end

Public Instance Methods

accept?(_subject, argument) click to toggle source
# File lib/gamefic/query/text.rb, line 37
def accept? _subject, argument
  match? argument
end
argument() click to toggle source
# File lib/gamefic/query/text.rb, line 15
def argument
  arguments.first
end
filter(_subject, token)
Alias for: query
precision() click to toggle source
# File lib/gamefic/query/text.rb, line 33
def precision
  0
end
query(_subject, token) click to toggle source
# File lib/gamefic/query/text.rb, line 24
def query _subject, token
  if match? token
    Result.new(token, '')
  else
    Result.new(nil, token)
  end
end
Also aliased as: filter
select(_subject) click to toggle source

@return [String, Regexp]

# File lib/gamefic/query/text.rb, line 20
def select(_subject)
  argument
end

Private Instance Methods

match?(token) click to toggle source
# File lib/gamefic/query/text.rb, line 43
def match? token
  return false unless token.is_a?(String) && !token.empty?

  case argument
  when Regexp
    token =~ argument
  else
    token == argument
  end
end
validate_argument() click to toggle source
# File lib/gamefic/query/text.rb, line 54
def validate_argument
  return if argument.is_a?(String) || argument.is_a?(Regexp)

  raise ArgumentError, 'Invalid text query argument'
end