Class: Gamefic::Query::Text
- Inherits:
-
Base
- Object
- Base
- Gamefic::Query::Text
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, #rank, #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 { |a|
if (a.kind_of?(Symbol) or a.kind_of?(String)) and !a.to_s.end_with?('?')
raise ArgumentError.new("Text query arguments can only be boolean method names (:method?) or regular expressions")
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
12
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 12
def resolve(subject, token, continued: false)
parts = token.split(Matchable::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(' '))
else
if matches.length == parts.length
Matches.new([matches.join(' ')], matches.join(' '), '')
else
Matches.new([], '', parts.join(' '))
end
end
end
|