class Mmonews::MmorpgScraper

Constants

BASE_URL
SOURCE

Attributes

page_scraper[RW]
url[RW]

Public Class Methods

new() click to toggle source
# File lib/mmonews/mmorpg_scraper.rb, line 8
def initialize
  self.url =  BASE_URL + '/articles'
  self.page_scraper = Mmonews::Scraper.new(url)
end

Public Instance Methods

create_articles() click to toggle source
# File lib/mmonews/mmorpg_scraper.rb, line 17
def create_articles
  page.collect do |p|
    article_url = BASE_URL + p.search('h1 a.title').attribute('href').value.strip
    author = p.search('p.body span.desc a').text

    article = {
      title: p.search('h1 a.title').text,
      date_published: p.search('p.body span.desc').text.gsub(" by #{author}", ""),
      author: author,
      source: SOURCE,
      url: article_url,
      summary: p.search('p.body').text
    }
    Mmonews::Article.create(article)
  end
end
page() click to toggle source
# File lib/mmonews/mmorpg_scraper.rb, line 13
def page
  @page ||= page_scraper.document.search('.entry')
end