Class: XMLScan::XMLScanner

Inherits:
Object
  • Object
show all
Extended by:
OptRegexp
Defined in:
lib/xmlscan/scanner.rb,
lib/xmlscan/xmlchar.rb

Direct Known Subclasses

HTMLScanner, XMLParser

Defined Under Namespace

Modules: OptRegexp, StrictChar

Constant Summary

Constants included from OptRegexp

OptRegexp::RE_ENCODINGS, OptRegexp::RE_ENCODING_OPTIONS, OptRegexp::UTFSTR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visitor) ⇒ XMLScanner

Returns a new instance of XMLScanner.



301
302
303
304
305
306
# File 'lib/xmlscan/scanner.rb', line 301

def initialize(visitor)
  @visitor = visitor
  @decoration = nil
  @src = nil
  @optkey = nil
end

Instance Attribute Details

#optkeyObject

Returns the value of attribute optkey.



308
309
310
# File 'lib/xmlscan/scanner.rb', line 308

def optkey
  @optkey
end

Class Method Details

.apply_option(instance, option) ⇒ Object



267
268
269
# File 'lib/xmlscan/scanner.rb', line 267

def apply_option(instance, option)
  instance.__send__ "apply_option_#{option}"
end

.apply_options(instance, options) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/xmlscan/scanner.rb', line 271

def apply_options(instance, options)
  h = {}
  options.each { |i| h[i.to_s] = true }
  options = h
  ancestors.each { |klass|
    if klass.respond_to? :provided_options then
      klass.provided_options.each { |i|
        if options.include? i then
          options.delete i
          klass.apply_option instance, i
        end
      }
    end
  }
  unless options.empty? then
    raise ArgumentError, "undefined option `#{options.keys[0]}'"
  end
  instance
end

.new(visitor, *options) ⇒ Object



292
293
294
295
# File 'lib/xmlscan/scanner.rb', line 292

def new(visitor, *options)
  instance = super(visitor)
  apply_options instance, options
end

.provided_optionsObject



259
260
261
262
263
264
265
# File 'lib/xmlscan/scanner.rb', line 259

def provided_options
  options = []
  private_instance_methods.each { |i|
    options.push $' if /\Aapply_option_/ =~ i
  }
  options
end

Instance Method Details

#linenoObject



322
323
324
# File 'lib/xmlscan/scanner.rb', line 322

def lineno
  @src && @src.lineno
end

#opt_encodingObject



310
# File 'lib/xmlscan/scanner.rb', line 310

def opt_encoding() OptRegexp::RE_ENCODINGS[optkey] end

#parse_document(src) ⇒ Object Also known as: parse



1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/xmlscan/scanner.rb', line 1113

def parse_document(src)
  @src = make_source(src)
  begin
    scan_document
  ensure
    @src = nil
  end
  self
end

#pathObject



326
327
328
# File 'lib/xmlscan/scanner.rb', line 326

def path
  @src && @src.path
end

#sourceObject



330
331
332
# File 'lib/xmlscan/scanner.rb', line 330

def source
  @src.source
end