Module: ColRead::Core

Included in:
Text
Defined in:
lib/colread.rb

Instance Method Summary collapse

Instance Method Details

#chapters(url) ⇒ Object



17
18
19
20
# File 'lib/colread.rb', line 17

def chapters url
  doc = Nokogiri::HTML(open(url))
  doc.css('a').group_by{|a| a.indent}.sort_by{|a| a.last.count}.last.last
end

#contents(chapters) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/colread.rb', line 22

def contents chapters
  chapters.each do |a|
    href=a['href'].start_with?('http') ? a['href'] : @root+a['href']
    source = open(href).read.encode('utf-8')
    content=Nokogiri::HTML(Readability::Document.new(source).content).text
    yield [a.text, content]
  end
end