Class: HtmlBeautifier::Parser

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

Direct Known Subclasses

HtmlParser

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Parser.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(&blk)
  @maps = []
  yield self if block_given?
end

Class Method Details

.debug(match, method) ⇒ Object



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

def self.debug(match, method)
  if defined? @debug_block
    @debug_block.call(match, method)
  end
end

.debug_block(&blk) ⇒ Object



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

def self.debug_block(&blk)
  @debug_block = blk
end

Instance Method Details

#map(pattern, method) ⇒ Object



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

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

#scan(subject, receiver) ⇒ Object



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

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

#source_line_numberObject



36
37
38
# File 'lib/htmlbeautifier/parser.rb', line 36

def source_line_number
  [source_so_far.chomp.split(/\n/).count, 1].max
end

#source_so_farObject



32
33
34
# File 'lib/htmlbeautifier/parser.rb', line 32

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