Class: Boilerpipe::SAX::TagActions::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/boilerpipe/sax/tag_actions/font.rb

Overview

Special TagAction for the <FONT> tag, which keeps track of the absolute and relative font size.

Constant Summary collapse

FONT_SIZE =
/([\+\-]?)([0-9])/

Instance Method Summary collapse

Instance Method Details

#changes_tag_level?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/boilerpipe/sax/tag_actions/font.rb', line 25

def changes_tag_level?
  false
end

#end_tag(handler, name) ⇒ Object



20
21
22
23
# File 'lib/boilerpipe/sax/tag_actions/font.rb', line 20

def end_tag(handler, name)
  handler.font_size_stack.pop
  false
end

#relative(font_size_stack, rel, val) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/boilerpipe/sax/tag_actions/font.rb', line 29

def relative(font_size_stack, rel, val)
  prev_size = font_size_stack.reverse_each.find { |s| !s.nil? }
  prev_size = 3 if prev_size.nil?

  size = if rel == '+'
           prev_size + val
         else
           prev_size - val
         end
end

#start(handler, name, attrs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/boilerpipe/sax/tag_actions/font.rb', line 7

def start(handler, name, attrs)
  m = FONT_SIZE.match attrs['size']
  if m
    rel = m[1]
    val = m[2].to_i # absolute
    size = rel.empty? ? val : relative(handler.font_size_stack, rel, val)
    handler.font_size_stack << size
  else
    handler.font_size_stack << nil
  end
  false
end