Sha256: 1ab0dd9a5ae3481232adebd1cd8cae1c689c408fd7a003adffdd3821c951a0f9

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# -*- coding: utf-8 -*-
module ConsadoleAggregator
  module NikkanSports
    module Parser
      module List
        BASE_URI = URI.parse('http://www.nikkansports.com/soccer/jleague/team/co-team.html')

        Element = Struct.new :uri, :title, :post_date, :has_image? do
          def initialize element
            self['uri'] = URI.parse(element.at('a')['href'])
            self['title'] = element.at('a').text
            self['post_date'] = Time.strptime(element.at('span').text.match(/\d+日\d+:\d+/).to_s, '%d日%H:%M')
            self['has_image?'] = !element.at('img').nil?
          end
        end

        def List.parse doc
          doc.search('div#topNewsInner ul.newsList01 li').map{|element| Element.new element}
        end
      end

      module Entry
        IMAGE_BASE_URI = URI.parse('http://cache2.nipc.jp/soccer/news/')

        def Entry.parse doc, uri = nil
          entry = NikkanSports::Entry.new
          entry.uri = uri if uri
          entry.title = doc.at('h1').text
          entry.text = doc.search('p')[0...-1].to_s
          entry.post_date = Time.strptime(doc.search('p').last.text.match(/\d+年\d+月\d+日\d+時\d+分/).to_s, '%Y年%m月%d日%H時%M分')
          entry.image = Image.new(IMAGE_BASE_URI + image['src'].sub(/\.jpg$/, '-big.jpg'), image['alt']) unless doc.at('img').nil?
          return entry
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
consadole_aggregator-0.0.2 lib/consadole_aggregator/nikkan_sports/parser.rb
consadole_aggregator-0.0.0 lib/consadole_aggregator/nikkan_sports/parser.rb