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

Class Method Details

.fuzzy(selection, token) ⇒ Result

Parameters:

Returns:



64
65
66
67
68
# File 'lib/gamefic/scanner.rb', line 64

def self.fuzzy selection, token
  return scan_text(selection, token) unless selection.is_a?(Array)

  scan_strict_or_fuzzy(selection, token, :select_fuzzy)
end

.scan(selection, token) ⇒ Result

Scan entities against a token.

Parameters:

Returns:



47
48
49
50
# File 'lib/gamefic/scanner.rb', line 47

def self.scan selection, token
  strict_result = strict(selection, token)
  strict_result.matched.empty? ? fuzzy(selection, token) : strict_result
end

.strict(selection, token) ⇒ Result

Parameters:

Returns:



55
56
57
58
59
# File 'lib/gamefic/scanner.rb', line 55

def self.strict selection, token
  return Result.new(selection, token, '', token) unless selection.is_a?(Array)

  scan_strict_or_fuzzy(selection, token, :select_strict)
end