Class: Textoken::Scanner

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

Overview

Scanner finds tokens in a word with regexp If word does not match regexp returns an empty Array

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word, regexp) ⇒ Scanner

Returns a new instance of Scanner.



7
8
9
10
11
# File 'lib/textoken/scanner.rb', line 7

def initialize(word, regexp)
  @word       = word
  @regexp     = regexp
  check_types
end

Instance Attribute Details

#regexpObject (readonly)

Returns the value of attribute regexp.



5
6
7
# File 'lib/textoken/scanner.rb', line 5

def regexp
  @regexp
end

#wordObject (readonly)

Returns the value of attribute word.



5
6
7
# File 'lib/textoken/scanner.rb', line 5

def word
  @word
end

Instance Method Details

#resultObject



13
14
15
16
# File 'lib/textoken/scanner.rb', line 13

def result
  scan = word.scan(regexp)
  scan.length > 0 ? partition(scan, word) : nil
end