Class: OLD::SCPArticleLoader
- Inherits:
-
Object
- Object
- OLD::SCPArticleLoader
- Defined in:
- lib/scp-article-loader.rb
Instance Method Summary collapse
- #article ⇒ Object
-
#initialize(item_no, option) ⇒ SCPArticleLoader
constructor
A new instance of SCPArticleLoader.
- #title ⇒ Object
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
#article ⇒ Object
29 30 31 |
# File 'lib/scp-article-loader.rb', line 29 def article() return @article end |
#title ⇒ Object
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 |