class Gamefic::Query::Text

Public Class Methods

new(*arguments) click to toggle source
Calls superclass method Gamefic::Query::Base::new
# File lib/gamefic/query/text.rb, line 4
def initialize *arguments
  arguments.each do |a|
    if (a.kind_of?(Symbol) || a.kind_of?(String)) && !a.to_s.end_with?('?')
      raise ArgumentError.new("Text query arguments can only be boolean method names (:method?) or regular expressions")
    end
  end
  super
end

Public Instance Methods

accept?(entity) click to toggle source
Calls superclass method Gamefic::Query::Base#accept?
# File lib/gamefic/query/text.rb, line 37
def accept? entity
  return false unless entity.kind_of?(String) and !entity.empty?
  super
end
include?(_subject, token) click to toggle source
# File lib/gamefic/query/text.rb, line 33
def include? _subject, token
  accept?(token)
end
precision() click to toggle source
# File lib/gamefic/query/text.rb, line 42
def precision
  0
end
resolve(_subject, token, continued: false) click to toggle source
# File lib/gamefic/query/text.rb, line 13
def resolve _subject, token, continued: false
  return Matches.new([], '', token) unless accept?(token)
  parts = token.split(Keywords::SPLIT_REGEXP)
  cursor = []
  matches = []
  i = 0
  parts.each { |w|
    cursor.push w
    matches = cursor if accept?(cursor.join(' '))
    i += 1
  }
  if continued
    Matches.new([matches.join(' ')], matches.join(' '), parts[i..-1].join(' '))
  elsif matches.length == parts.length
    Matches.new([matches.join(' ')], matches.join(' '), '')
  else
    Matches.new([], '', parts.join(' '))
  end
end