Class: Gamefic::Query::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/gamefic/query/text.rb

Overview

A special query that handles text instead of entities.

Instance Attribute Summary

Attributes inherited from Base

#arguments

Instance Method Summary collapse

Methods inherited from Base

#bind, #inspect, #name, plain, #span, span

Constructor Details

#initialize(argument = /.*/, name: self.class.name) ⇒ Text

Returns a new instance of Text.

Parameters:

  • argument (String, Regexp) (defaults to: /.*/)
  • name (String, nil) (defaults to: self.class.name)


10
11
12
13
# File 'lib/gamefic/query/text.rb', line 10

def initialize(argument = /.*/, name: self.class.name)
  super(argument, name: name)
  validate_argument
end

Instance Method Details

#accept?(_subject, token) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gamefic/query/text.rb', line 36

def accept?(_subject, token)
  match?(token)
end

#argumentObject



15
16
17
# File 'lib/gamefic/query/text.rb', line 15

def argument
  arguments.first
end

#filter(_subject, token) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/gamefic/query/text.rb', line 24

def filter(_subject, token)
  if match? token
    Result.new(token, '')
  else
    Result.new(nil, token)
  end
end

#precisionObject



32
33
34
# File 'lib/gamefic/query/text.rb', line 32

def precision
  -10_000
end

#select(_subject) ⇒ String, Regexp

Returns:



20
21
22
# File 'lib/gamefic/query/text.rb', line 20

def select(_subject)
  argument
end