Class: RTF::Converters::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/rtf/converters/html.rb

Defined Under Namespace

Modules: Helpers Classes: Node, NodeSet

Instance Method Summary collapse

Constructor Details

#initialize(html, options = {}) ⇒ HTML

Returns a new instance of HTML.



7
8
9
10
# File 'lib/rtf/converters/html.rb', line 7

def initialize(html, options = {})
  html  = options[:noclean] ? html : clean(html, options[:tidy_options] || {})
  @html = Nokogiri::HTML::Document.parse(html)
end

Instance Method Details

#to_rtf(options = {}) ⇒ Object



12
13
14
# File 'lib/rtf/converters/html.rb', line 12

def to_rtf(options = {})
  to_rtf_document(options).to_rtf
end

#to_rtf_document(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rtf/converters/html.rb', line 16

def to_rtf_document(options = {})
  font  = Helpers.font(options[:font] || :default)
  nodes = NodeSet.new @html.css('body').children

  RTF::Document.new(font).tap do |rtf|
    nodes.to_rtf(rtf)
  end
end