Class: Gamefic::Scanner::Result

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

Overview

The result of an attempt to scan objects against a token in a Scanner. It provides an array of matching objects, the text that matched them, and the text that remains unmatched.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scanned, token, matched, remainder, processor) ⇒ Result

Returns a new instance of Result.



33
34
35
36
37
38
39
# File 'lib/gamefic/scanner/result.rb', line 33

def initialize scanned, token, matched, remainder, processor
  @scanned = scanned
  @token = token
  @matched = matched
  @remainder = remainder
  @processor = processor
end

Instance Attribute Details

#matchedArray<Entity>, String (readonly) Also known as: match

The matched objects

Returns:



23
24
25
# File 'lib/gamefic/scanner/result.rb', line 23

def matched
  @matched
end

#processorObject (readonly)

Returns the value of attribute processor.



31
32
33
# File 'lib/gamefic/scanner/result.rb', line 31

def processor
  @processor
end

#remainderString (readonly)

The remaining (unmatched) portion of the token

Returns:



29
30
31
# File 'lib/gamefic/scanner/result.rb', line 29

def remainder
  @remainder
end

#scannedArray<Entity>, ... (readonly)

The scanned objects

Returns:



13
14
15
# File 'lib/gamefic/scanner/result.rb', line 13

def scanned
  @scanned
end

#tokenString (readonly)

The scanned token

Returns:



18
19
20
# File 'lib/gamefic/scanner/result.rb', line 18

def token
  @token
end

Class Method Details

.unmatched(scanned, token, processor) ⇒ Object



58
59
60
# File 'lib/gamefic/scanner/result.rb', line 58

def self.unmatched scanned, token, processor
  new(scanned, token, [], token, processor)
end

Instance Method Details

#filter(*args) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/gamefic/scanner/result.rb', line 48

def filter *args
  Scanner::Result.new(
    scanned,
    token,
    match.that_are(*args),
    remainder,
    processor
  )
end

#strictnessInteger

The strictness of the scanner that produced this result.

Returns:

  • (Integer)


44
45
46
# File 'lib/gamefic/scanner/result.rb', line 44

def strictness
  @strictness ||= Scanner.strictness(processor)
end