Class: OLD::SCPArticleLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/scp-article-loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(item_no, option) ⇒ SCPArticleLoader

Returns a new instance of SCPArticleLoader.



7
8
9
10
11
12
13
14
15
16
# File 'lib/scp-article-loader.rb', line 7

def initialize(item_no, option)
  @item_no = item_no
  @option = option
  @agent = Mechanize.new
  url = "http://#{get_endpoint(@option[:locale])}/scp-#{@item_no}"
  page = @agent.get(url)
  doc = Nokogiri::HTML(page.content.toutf8)
  @article = doc.xpath('//*[@id="page-content"]').first
  @title = nil
end

Instance Method Details

#articleObject



29
30
31
# File 'lib/scp-article-loader.rb', line 29

def article()
  return @article
end

#titleObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/scp-article-loader.rb', line 18

def title()
  return @title if @title
  series = @item_no.to_i / 1000 + 1
  url = "http://www.scp-wiki.net/scp-series" +
    (series > 1 ? "-#{series}" : "")
  page = @agent.get(url)
  doc = Nokogiri::HTML(page.content.toutf8)
  article = doc.at('//*[@class="content-panel standalone series"]')
  @title = article.text.match("SCP-#{@item_no} - (.*)$").to_s
end