Class: Gamefic::Query::Text
- Inherits:
-
Base
show all
- Defined in:
- lib/gamefic/query/text.rb
Constant Summary
Constants inherited
from Base
Base::NEST_REGEXP
Instance Attribute Summary
Attributes inherited from Base
#arguments
Instance Method Summary
collapse
Methods inherited from Base
#ambiguous?, #context_from, #signature
Constructor Details
#initialize(*arguments) ⇒ Text
4
5
6
7
8
9
10
11
|
# 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
|
Instance Method Details
#accept?(entity) ⇒ Boolean
37
38
39
40
|
# 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) ⇒ Boolean
33
34
35
|
# File 'lib/gamefic/query/text.rb', line 33
def include? _subject, token
accept?(token)
end
|
#precision ⇒ Object
42
43
44
|
# File 'lib/gamefic/query/text.rb', line 42
def precision
0
end
|
#resolve(_subject, token, continued: false) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 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
|