Sha256: da5cb51868fb2101900a7ada4a3d2e4f11f4f7273ebd8203d8383254f0066f13

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 Bytes

Contents

require 'nokogiri'
require 'mechanize'
require_relative 'locale'

module OLD
  class SCPArticleLoader
    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

    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

    def article()
      return @article
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
old-0.1.1 lib/scp-article-loader.rb
old-0.1.0 lib/scp-article-loader.rb