Method: Bcat::HeadParser#parse
- Defined in:
- lib/bcat/html.rb
#parse(buf = @buf) ⇒ Object
Parses buf into head and body parts. Basic approach is to eat anything possibly body related until we hit text or a body element.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/bcat/html.rb', line 74 def parse(buf=@buf) if @html.nil? if buf =~ /\A\s*[<]/m @html = true elsif buf =~ /\A\s*[^<]/m @html = false end end while !buf.empty? buf.sub!(/\A(\s+)/m) { @head << $1 ; '' } matched = HEAD_TOKS.any? do |tok| buf.sub!(tok) do @head << $1 '' end end break unless matched end if buf.empty? buf elsif BODY_TOKS.any? { |tok| buf =~ tok } @body = buf nil else buf end end |