Class: TinyHNews::ToMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_hnews/to_markdown.rb

Class Method Summary collapse

Class Method Details

.fetch(url) ⇒ Object



20
21
22
# File 'lib/tiny_hnews/to_markdown.rb', line 20

def self.fetch(url)
  Faraday.get(url).body
end

.from_hml(html) ⇒ Object



16
17
18
# File 'lib/tiny_hnews/to_markdown.rb', line 16

def self.from_hml(html)
  ReverseMarkdown.convert(html, unknown_tags: :bypass)
end

.from_url(url) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/tiny_hnews/to_markdown.rb', line 6

def self.from_url(url)
  html = fetch(url)
  doc = Nokogiri::HTML(html)
  body = doc.at("body").to_html
  from_hml(body)
rescue StandardError => e
  puts "[TinyHNews::ToMarkdown] Error fetching or converting URL #{url}: #{e.message}"
  nil
end