Module: Readability::Readable

Includes:
Harmonizable
Included in:
Nokogiri::HTML::Document
Defined in:
lib/readability/readable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Harmonizable

#execute_js, #harmony_page, #load_js, #parse, #window

Instance Attribute Details

#read_marginObject



13
14
15
# File 'lib/readability/readable.rb', line 13

def read_margin
  @read_margin ||= Readability::Margin::MEDIUM
end

#read_sizeObject



9
10
11
# File 'lib/readability/readable.rb', line 9

def read_size
  @read_size ||= Readability::Size::MEDIUM
end

#read_styleObject



5
6
7
# File 'lib/readability/readable.rb', line 5

def read_style
  @read_style ||= Readability::Style::NEWSPAPER
end

Instance Method Details

#to_readable(args = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/readability/readable.rb', line 25

def to_readable(args = {})
  # dup document
  readable_doc = self.dup
  
  # remove all script and iframe tags
  readable_doc.remove('script')
  readable_doc.remove('iframe')
  
  readable_doc.harmony_page do |page|
    # Set parameters
    page.window.readStyle = @read_style
    page.window.readSize = @read_size
    page.window.readMargin = @read_margin
    
    # execute readability.js
    page.load(File.join(File.dirname(__FILE__), 'js', 'readability.js'))
  end
  
  # remove all linebreaks if needed
  readable_doc.remove('br') if args[:remove_br]
  
  # remove footer if needed
  readable_doc.remove('#readFooter') if args[:remove_footer]
  
  # return <div id="readInner">...</div> if content_only
  if args[:content_only]
    return readable_doc.at_css("#readInner")
  end
  
  # return document root
  readable_doc.root
end

#to_readable!(args = {}) ⇒ Object



58
59
60
# File 'lib/readability/readable.rb', line 58

def to_readable!(args = {})
  self.root = to_readable(args)
end


19
20
21
# File 'lib/readability/readable.rb', line 19

def unlink(*paths)
  self.search(*paths).unlink
end