Class: Textoken::Scanner
- Inherits:
-
Object
- Object
- Textoken::Scanner
- 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
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
-
#initialize(word, regexp) ⇒ Scanner
constructor
A new instance of Scanner.
- #result ⇒ Object
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
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
5 6 7 |
# File 'lib/textoken/scanner.rb', line 5 def regexp @regexp end |
#word ⇒ Object (readonly)
Returns the value of attribute word.
5 6 7 |
# File 'lib/textoken/scanner.rb', line 5 def word @word end |
Instance Method Details
#result ⇒ Object
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 |