-
Notifications
You must be signed in to change notification settings - Fork 5
/
article.rb
35 lines (28 loc) · 926 Bytes
/
article.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require './init.rb'
class Article
attr_reader :export_id, :import_id, :articles_with_urls, :parsed_body
attr_accessor :body
include FixRedirects
def initialize(body, export_id, import_id)
@body = body
@parsed_body = Nokogiri::HTML.parse(@body)
@export_id = export_id
@import_id = import_id
@anchors = @parsed_body.xpath("//a")
end
def should_transform_urls?
@anchors.each {|anchor| return true if anchor_is_a_help_center_reference?(anchor)}
end
def anchor_is_a_help_center_reference?(anchor)
parsed_uri(anchor).host == EXPORT_CUSTOM_DOMAIN
end
def parsed_uri(anchor)
URI(anchor[:href])
end
def update_imported_article
@body = @parsed_body
article = ImportWorkspace.articles.find(id: import_id)
article.body = @body
article = ImportWorkspace.articles.save(article)
end
end