class NpbHeadline::Base
Constants
- SIZE
- SOURCE
Public Class Methods
new(team_id)
click to toggle source
# File lib/npb_headline/base.rb, line 10 def initialize(team_id) @team_id = team_id end
Public Instance Methods
articles()
click to toggle source
# File lib/npb_headline/base.rb, line 14 def articles _articles = [] doc.css('#NpbNewsSearch li').each do |li| article = {} li.css('a').each do |a| article[:link] = a.attribute('href').value article[:title] = a.content end li.css('em').each do |em| m = em.content.match /^((?<publisher>.+))\s(?<date>.+)$/ article[:publisher] = m[:publisher] article[:date] = m[:date] end _articles << article end _articles.shift(SIZE) end
Private Instance Methods
doc()
click to toggle source
# File lib/npb_headline/base.rb, line 39 def doc Nokogiri::HTML(open(url)) end
url()
click to toggle source
# File lib/npb_headline/base.rb, line 43 def url sprintf(SOURCE, @team_id) end