Class: HtmlBeautifier::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlbeautifier/parser.rb

Direct Known Subclasses

HtmlParser

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Parser

Returns a new instance of Parser.

Yields:

  • (_self)

Yield Parameters:


7
8
9
10
# File 'lib/htmlbeautifier/parser.rb', line 7

def initialize
  @maps = []
  yield self if block_given?
end

Instance Method Details

#map(pattern, method) ⇒ Object


12
13
14
# File 'lib/htmlbeautifier/parser.rb', line 12

def map(pattern, method)
  @maps << [pattern, method]
end

#scan(subject, receiver) ⇒ Object


16
17
18
19
# File 'lib/htmlbeautifier/parser.rb', line 16

def scan(subject, receiver)
  @scanner = StringScanner.new(subject)
  dispatch(receiver) until @scanner.eos?
end

#source_line_numberObject


25
26
27
# File 'lib/htmlbeautifier/parser.rb', line 25

def source_line_number
  [source_so_far.chomp.split(%r{\n}).count, 1].max
end

#source_so_farObject


21
22
23
# File 'lib/htmlbeautifier/parser.rb', line 21

def source_so_far
  @scanner.string[0...@scanner.pos]
end