Class: Gamefic::Scanner::Strict

Inherits:
Base
  • Object
show all
Defined in:
lib/gamefic/scanner/strict.rb

Overview

Strict token matching.

An entity will only match a word in a strict scan if the entire word matches one of the entity’s keywords.

Direct Known Subclasses

Fuzzy

Instance Attribute Summary

Attributes inherited from Base

#selection, #token

Instance Method Summary collapse

Methods inherited from Base

#initialize, scan

Constructor Details

This class inherits a constructor from Gamefic::Scanner::Base

Instance Method Details

#match_word(available, word) ⇒ Object



26
27
28
# File 'lib/gamefic/scanner/strict.rb', line 26

def match_word available, word
  available.select { |obj| obj.keywords.include?(word) }
end

#scanResult

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gamefic/scanner/strict.rb', line 12

def scan
  words = token.keywords
  available = selection.clone
  filtered = []
  words.each_with_index do |word, idx|
    tested = match_word(available, word)
    return matched_result(filtered, words[idx..].join(' ')) if tested.empty?

    filtered = tested
    available = filtered
  end
  matched_result filtered, ''
end