-
Notifications
You must be signed in to change notification settings - Fork 0
/
kawahigashi.rb
60 lines (55 loc) · 1.14 KB
/
kawahigashi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
# File : kawahigashi.rb
# Author : Kazune Takahashi
# Created : 1/16/2019, 10:54:10 PM
# Powered by Visual Studio Code
#
class Kawahigashi
require './news.rb'
require 'open-uri'
require 'nokogiri'
attr_accessor :year, :components, :texts
def initialize(url)
@year = nil
@components = nil
@texts = []
doc = nil
begin
page = URI.parse(url).read
# page = File.read(url)
doc = Nokogiri::HTML(page, url, "EUC-JP")
rescue
# 何もしない
end
if doc.nil?
return nil
end
x = doc.xpath("/html/body/h1")
if x && m = x.text.match(/(\d{4})年/)
@year = m[1].to_i
end
if @year.nil?
return nil
end
x = doc.xpath("/html/body/p")
if x
@components = []
x.each{|para|
n = News.new()
if n.make_news(para, :news)
@components << n
end
}
end
if @components.nil? || @components.empty?
return nil
end
@components.each{|news|
@texts << news.to_s
}
end
def valid?
!(@year.nil? || @components.nil? || @components.empty? ||
@texts.nil? || @texts.empty?)
end
end