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

#ambiguous, #arguments, #narrative

Instance Method Summary collapse

Methods inherited from Base

#ambiguous?, #inspect, #name, #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, argument) ⇒ Boolean

Returns:

  • (Boolean)


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

def accept? _subject, argument
  match? argument
end

#argumentObject



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

def argument
  arguments.first
end

#precisionObject



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

def precision
  0
end

#query(_subject, token) ⇒ Object Also known as: filter



24
25
26
27
28
29
30
# 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

#select(_subject) ⇒ String, Regexp

Returns:



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

def select(_subject)
  argument
end