class FFXIVScraper::Lodestone::News

Constants

CATEGORY
DetailContent
NewsContent

Public Class Methods

new(category = :notice) click to toggle source
# File lib/ffxiv_scraper/lodestone/news.rb, line 12
def initialize(category = :notice)
  @category = category
  set_locale
  unless CATEGORY.key?(category)
    raise "not found category. [" + category.to_s + "]"
  end
end

Public Instance Methods

get_news_url() click to toggle source
# File lib/ffxiv_scraper/lodestone/news.rb, line 20
def get_news_url
  return get_lodestone_url + "/news/category/#{CATEGORY[@category]}"
end
news_list(backnumber = 0) click to toggle source
# File lib/ffxiv_scraper/lodestone/news.rb, line 24
def news_list(backnumber = 0)
  news_list = []
  news_url = backnumber > 0 ? get_news_url << "?page=#{backnumber}" : get_news_url
  
  doc = open_html(news_url)
  doc.xpath('//li[@class="news__list"]').each do |news|
    news_list << NewsContent.new(@lang, news.xpath('.//time').text[/strftime\((\d+),/,1].to_i, 
                                  news.xpath('.//p').text, 
                                  news.xpath('.//a/@href').text, 
                                  news.xpath('.//p/span').text)
  end
  news_list.sort { |a, b| b.created_at <=> a.created_at }
end