Class: StringScanner

Inherits:
Object show all
Defined in:
lib/rpdf2txt-rockit/stringscanner.rb

Overview

Simple substitution for strscan in Ruby for users that lack strscan.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ StringScanner

Returns a new instance of StringScanner.



14
15
16
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 14

def initialize(string)
  @orig, @pointer = string, 0
end

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



12
13
14
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 12

def pointer
  @pointer
end

Instance Method Details

#check(regexp) ⇒ Object



30
31
32
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 30

def check(regexp)
  apply_regexp(regexp, false)
end

#restObject



22
23
24
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 22

def rest
  @orig[pointer..-1]
end

#rest?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 26

def rest?
  rest.length > 0
end

#scan(regexp) ⇒ Object



34
35
36
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 34

def scan(regexp)
  apply_regexp(regexp, true)
end

#stringObject



18
19
20
# File 'lib/rpdf2txt-rockit/stringscanner.rb', line 18

def string
  @orig
end