Module: Gamefic::Scanner
- Defined in:
- lib/gamefic/scanner.rb
Overview
A module for matching objects to tokens.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- NEST_REGEXP =
/ in | on | of | from | inside | from inside /
Class Method Summary collapse
-
.scan(objects, token) ⇒ Result
Scan entities against a token.
Class Method Details
.scan(objects, token) ⇒ Result
Scan entities against a token.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gamefic/scanner.rb', line 45 def self.scan objects, token # @note Theoretically, scanned objects only have to implement two # methods: # * #keywords => [Array<String>] # * #children => [Array<#keywords, #children>] words = token.keywords available = objects.clone filtered = [] if nested?(token) && objects.all?(&:children) denest(objects, token) else words.each_with_index do |word, idx| tested = select_strict(available, word) tested = select_fuzzy(available, word) if tested.empty? return Result.new(objects, token, filtered, words[idx..].join(' ')) if tested.empty? filtered = tested available = filtered end Result.new(objects, token, filtered, '') end end |