simple2ch 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +123 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/doc/Simple2ch/Board.html +711 -0
- data/doc/Simple2ch/Dat.html +502 -0
- data/doc/Simple2ch/DatParseException.html +131 -0
- data/doc/Simple2ch/KakoLogException.html +131 -0
- data/doc/Simple2ch/NotA2chUrlException.html +131 -0
- data/doc/Simple2ch/Res.html +1034 -0
- data/doc/Simple2ch/Simple2chException.html +127 -0
- data/doc/Simple2ch/Thre.html +792 -0
- data/doc/Simple2ch.html +314 -0
- data/doc/_index.html +214 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +111 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +111 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +215 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/simple2ch/board.rb +70 -0
- data/lib/simple2ch/dat.rb +57 -0
- data/lib/simple2ch/res.rb +70 -0
- data/lib/simple2ch/simple2ch_exception.rb +6 -0
- data/lib/simple2ch/thre.rb +49 -0
- data/lib/simple2ch/version.rb +3 -0
- data/lib/simple2ch.rb +31 -0
- data/simple2ch.gemspec +33 -0
- data/spec/board_spec.rb +45 -0
- data/spec/dat_spec.rb +27 -0
- data/spec/res_spec.rb +42 -0
- data/spec/simple2ch_spec.rb +33 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/thre_spec.rb +37 -0
- metadata +176 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>Method List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<script type="text/javascript" charset="utf-8">
|
23
|
+
if (window.top.frames.main) {
|
24
|
+
document.getElementById('base_target').target = 'main';
|
25
|
+
document.body.className = 'frames';
|
26
|
+
}
|
27
|
+
</script>
|
28
|
+
<div id="content">
|
29
|
+
<h1 id="full_list_header">Method List</h1>
|
30
|
+
<div id="nav">
|
31
|
+
|
32
|
+
<span><a target="_self" href="class_list.html">
|
33
|
+
Classes
|
34
|
+
</a></span>
|
35
|
+
|
36
|
+
<span><a target="_self" href="method_list.html">
|
37
|
+
Methods
|
38
|
+
</a></span>
|
39
|
+
|
40
|
+
<span><a target="_self" href="file_list.html">
|
41
|
+
Files
|
42
|
+
</a></span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
<div id="search">Search: <input type="text" /></div>
|
46
|
+
|
47
|
+
<ul id="full_list" class="method">
|
48
|
+
|
49
|
+
|
50
|
+
<li class="r1 ">
|
51
|
+
<span class='object_link'><a href="Simple2ch/Res.html#author-instance_method" title="Simple2ch::Res#author (method)">#author</a></span>
|
52
|
+
<small>Simple2ch::Res</small>
|
53
|
+
</li>
|
54
|
+
|
55
|
+
|
56
|
+
<li class="r2 ">
|
57
|
+
<span class='object_link'><a href="Simple2ch/Res.html#author_id-instance_method" title="Simple2ch::Res#author_id (method)">#author_id</a></span>
|
58
|
+
<small>Simple2ch::Res</small>
|
59
|
+
</li>
|
60
|
+
|
61
|
+
|
62
|
+
<li class="r1 ">
|
63
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#board-instance_method" title="Simple2ch::Thre#board (method)">#board</a></span>
|
64
|
+
<small>Simple2ch::Thre</small>
|
65
|
+
</li>
|
66
|
+
|
67
|
+
|
68
|
+
<li class="r2 ">
|
69
|
+
<span class='object_link'><a href="Simple2ch/Board.html#board_name-instance_method" title="Simple2ch::Board#board_name (method)">#board_name</a></span>
|
70
|
+
<small>Simple2ch::Board</small>
|
71
|
+
</li>
|
72
|
+
|
73
|
+
|
74
|
+
<li class="r1 ">
|
75
|
+
<span class='object_link'><a href="Simple2ch/Res.html#contents-instance_method" title="Simple2ch::Res#contents (method)">#contents</a></span>
|
76
|
+
<small>Simple2ch::Res</small>
|
77
|
+
</li>
|
78
|
+
|
79
|
+
|
80
|
+
<li class="r2 ">
|
81
|
+
<span class='object_link'><a href="Simple2ch/Res.html#date-instance_method" title="Simple2ch::Res#date (method)">#date</a></span>
|
82
|
+
<small>Simple2ch::Res</small>
|
83
|
+
</li>
|
84
|
+
|
85
|
+
|
86
|
+
<li class="r1 ">
|
87
|
+
<span class='object_link'><a href="Simple2ch.html#fetch-class_method" title="Simple2ch.fetch (method)">fetch</a></span>
|
88
|
+
<small>Simple2ch</small>
|
89
|
+
</li>
|
90
|
+
|
91
|
+
|
92
|
+
<li class="r2 ">
|
93
|
+
<span class='object_link'><a href="Simple2ch/Board.html#initialize-instance_method" title="Simple2ch::Board#initialize (method)">#initialize</a></span>
|
94
|
+
<small>Simple2ch::Board</small>
|
95
|
+
</li>
|
96
|
+
|
97
|
+
|
98
|
+
<li class="r1 ">
|
99
|
+
<span class='object_link'><a href="Simple2ch/Res.html#initialize-instance_method" title="Simple2ch::Res#initialize (method)">#initialize</a></span>
|
100
|
+
<small>Simple2ch::Res</small>
|
101
|
+
</li>
|
102
|
+
|
103
|
+
|
104
|
+
<li class="r2 ">
|
105
|
+
<span class='object_link'><a href="Simple2ch/Dat.html#initialize-instance_method" title="Simple2ch::Dat#initialize (method)">#initialize</a></span>
|
106
|
+
<small>Simple2ch::Dat</small>
|
107
|
+
</li>
|
108
|
+
|
109
|
+
|
110
|
+
<li class="r1 ">
|
111
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#initialize-instance_method" title="Simple2ch::Thre#initialize (method)">#initialize</a></span>
|
112
|
+
<small>Simple2ch::Thre</small>
|
113
|
+
</li>
|
114
|
+
|
115
|
+
|
116
|
+
<li class="r2 ">
|
117
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#kako_log%3F-instance_method" title="Simple2ch::Thre#kako_log? (method)">#kako_log?</a></span>
|
118
|
+
<small>Simple2ch::Thre</small>
|
119
|
+
</li>
|
120
|
+
|
121
|
+
|
122
|
+
<li class="r1 ">
|
123
|
+
<span class='object_link'><a href="Simple2ch/Dat.html#kako_log%3F-instance_method" title="Simple2ch::Dat#kako_log? (method)">#kako_log?</a></span>
|
124
|
+
<small>Simple2ch::Dat</small>
|
125
|
+
</li>
|
126
|
+
|
127
|
+
|
128
|
+
<li class="r2 ">
|
129
|
+
<span class='object_link'><a href="Simple2ch/Res.html#mail-instance_method" title="Simple2ch::Res#mail (method)">#mail</a></span>
|
130
|
+
<small>Simple2ch::Res</small>
|
131
|
+
</li>
|
132
|
+
|
133
|
+
|
134
|
+
<li class="r1 ">
|
135
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#num_of_response-instance_method" title="Simple2ch::Thre#num_of_response (method)">#num_of_response</a></span>
|
136
|
+
<small>Simple2ch::Thre</small>
|
137
|
+
</li>
|
138
|
+
|
139
|
+
|
140
|
+
<li class="r2 ">
|
141
|
+
<span class='object_link'><a href="Simple2ch/Res.html#parse-class_method" title="Simple2ch::Res.parse (method)">parse</a></span>
|
142
|
+
<small>Simple2ch::Res</small>
|
143
|
+
</li>
|
144
|
+
|
145
|
+
|
146
|
+
<li class="r1 ">
|
147
|
+
<span class='object_link'><a href="Simple2ch/Res.html#res_num-instance_method" title="Simple2ch::Res#res_num (method)">#res_num</a></span>
|
148
|
+
<small>Simple2ch::Res</small>
|
149
|
+
</li>
|
150
|
+
|
151
|
+
|
152
|
+
<li class="r2 ">
|
153
|
+
<span class='object_link'><a href="Simple2ch/Dat.html#reses-instance_method" title="Simple2ch::Dat#reses (method)">#reses</a></span>
|
154
|
+
<small>Simple2ch::Dat</small>
|
155
|
+
</li>
|
156
|
+
|
157
|
+
|
158
|
+
<li class="r1 ">
|
159
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#reses-instance_method" title="Simple2ch::Thre#reses (method)">#reses</a></span>
|
160
|
+
<small>Simple2ch::Thre</small>
|
161
|
+
</li>
|
162
|
+
|
163
|
+
|
164
|
+
<li class="r2 ">
|
165
|
+
<span class='object_link'><a href="Simple2ch.html#root-class_method" title="Simple2ch.root (method)">root</a></span>
|
166
|
+
<small>Simple2ch</small>
|
167
|
+
</li>
|
168
|
+
|
169
|
+
|
170
|
+
<li class="r1 ">
|
171
|
+
<span class='object_link'><a href="Simple2ch/Board.html#server_name-instance_method" title="Simple2ch::Board#server_name (method)">#server_name</a></span>
|
172
|
+
<small>Simple2ch::Board</small>
|
173
|
+
</li>
|
174
|
+
|
175
|
+
|
176
|
+
<li class="r2 ">
|
177
|
+
<span class='object_link'><a href="Simple2ch/Dat.html#thread_key-instance_method" title="Simple2ch::Dat#thread_key (method)">#thread_key</a></span>
|
178
|
+
<small>Simple2ch::Dat</small>
|
179
|
+
</li>
|
180
|
+
|
181
|
+
|
182
|
+
<li class="r1 ">
|
183
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#thread_key-instance_method" title="Simple2ch::Thre#thread_key (method)">#thread_key</a></span>
|
184
|
+
<small>Simple2ch::Thre</small>
|
185
|
+
</li>
|
186
|
+
|
187
|
+
|
188
|
+
<li class="r2 ">
|
189
|
+
<span class='object_link'><a href="Simple2ch/Board.html#threads-instance_method" title="Simple2ch::Board#threads (method)">#threads</a></span>
|
190
|
+
<small>Simple2ch::Board</small>
|
191
|
+
</li>
|
192
|
+
|
193
|
+
|
194
|
+
<li class="r1 ">
|
195
|
+
<span class='object_link'><a href="Simple2ch/Board.html#title-instance_method" title="Simple2ch::Board#title (method)">#title</a></span>
|
196
|
+
<small>Simple2ch::Board</small>
|
197
|
+
</li>
|
198
|
+
|
199
|
+
|
200
|
+
<li class="r2 ">
|
201
|
+
<span class='object_link'><a href="Simple2ch/Thre.html#title-instance_method" title="Simple2ch::Thre#title (method)">#title</a></span>
|
202
|
+
<small>Simple2ch::Thre</small>
|
203
|
+
</li>
|
204
|
+
|
205
|
+
|
206
|
+
<li class="r1 ">
|
207
|
+
<span class='object_link'><a href="Simple2ch/Board.html#url-instance_method" title="Simple2ch::Board#url (method)">#url</a></span>
|
208
|
+
<small>Simple2ch::Board</small>
|
209
|
+
</li>
|
210
|
+
|
211
|
+
|
212
|
+
</ul>
|
213
|
+
</div>
|
214
|
+
</body>
|
215
|
+
</html>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.4
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!top-level-namespace.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Top Level Namespace</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Top Level Namespace
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
</dl>
|
82
|
+
<div class="clear"></div>
|
83
|
+
|
84
|
+
<h2>Defined Under Namespace</h2>
|
85
|
+
<p class="children">
|
86
|
+
|
87
|
+
|
88
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Simple2ch.html" title="Simple2ch (module)">Simple2ch</a></span>
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
</p>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
<div id="footer">
|
106
|
+
Generated on Sun Sep 7 11:29:29 2014 by
|
107
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
+
0.8.7.4 (ruby-2.1.2).
|
109
|
+
</div>
|
110
|
+
|
111
|
+
</body>
|
112
|
+
</html>
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Simple2ch
|
2
|
+
class Board
|
3
|
+
# @return [URI] 板のURL
|
4
|
+
attr_reader :url
|
5
|
+
# @return [String] 板のタイトル
|
6
|
+
attr_reader :title
|
7
|
+
# @return [String] サーバ名
|
8
|
+
attr_reader :server_name
|
9
|
+
# @return [String] 板の名前(コンピュータ名)
|
10
|
+
attr_reader :board_name
|
11
|
+
|
12
|
+
|
13
|
+
# @param [String] title 板の名前
|
14
|
+
# @param [String] url 板のURL
|
15
|
+
def initialize(title, url)
|
16
|
+
@server_name = @board_name = nil
|
17
|
+
@url = validate_url url
|
18
|
+
@title = title
|
19
|
+
@thres = []
|
20
|
+
end
|
21
|
+
|
22
|
+
# 板に属する全てのスレッドを返す
|
23
|
+
# @return [Array<Thre>] 板に属する全てのスレッド
|
24
|
+
def threads
|
25
|
+
if @thres.size > 0
|
26
|
+
@thres
|
27
|
+
else
|
28
|
+
fetch_all_thres
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
# URLが正しいかバリデーションする
|
34
|
+
# @param [URI] url
|
35
|
+
# @raise [Simple2ch::NotA2chUrlException] 2chのフォーマットで無いURLを渡したときに発生
|
36
|
+
# @raise [URI::InvalidURIError] そもそもURLのフォーマットで無いときに発生
|
37
|
+
def validate_url(url)
|
38
|
+
sp_uri = URI.parse url
|
39
|
+
board_url = ''
|
40
|
+
|
41
|
+
if sp_uri.host.index '2ch'
|
42
|
+
case url
|
43
|
+
when /http:\/\/(.+)\.2ch.(net|sc)\/test\/read.cgi\/(.+)\/([0-9]+)/,
|
44
|
+
/http:\/\/(.+)\.2ch\.(net|sc)\/(.+)\/subject\.txt/,
|
45
|
+
/http:\/\/(.+)\.2ch\.(net|sc)\/(.+)\//,
|
46
|
+
/http:\/\/(.+)\.2ch\.(net|sc)\/(\w+)/,
|
47
|
+
/http:\/\/(.+)\.2ch.(net|sc)\/(.+)\/dat\/([0-9]+)\.dat/
|
48
|
+
@server_name = $1; @board_name = $3
|
49
|
+
board_url = URI.parse("http://#{$1}.2ch.sc/#{$3}/")
|
50
|
+
else
|
51
|
+
raise NotA2chUrlException
|
52
|
+
end
|
53
|
+
else
|
54
|
+
raise NotA2chUrlException
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# 板に属する全てのスレッドをsubject.txtから取得する
|
59
|
+
# @return [Array<Thre>] 板に属する全てのスレッド
|
60
|
+
def fetch_all_thres
|
61
|
+
subject_url = @url+'subject.txt'
|
62
|
+
|
63
|
+
subject_txt = Simple2ch.fetch(subject_url)
|
64
|
+
subject_txt.each_line do |line|
|
65
|
+
@thres << Thre.new(self, line)
|
66
|
+
end
|
67
|
+
@thres
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Simple2ch
|
2
|
+
class Dat
|
3
|
+
# @return [String] スレッドキー
|
4
|
+
attr_reader :thread_key
|
5
|
+
|
6
|
+
# @param [Thre] thre スレッド
|
7
|
+
def initialize(thre)
|
8
|
+
@thre = thre
|
9
|
+
@thread_key = thre.thread_key
|
10
|
+
@data = nil
|
11
|
+
@reses = nil
|
12
|
+
@f_kako_log = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# Datを解析して、レスを返す
|
16
|
+
# @return [Array<Res>] レス
|
17
|
+
def reses
|
18
|
+
@reses || parse_dat[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Datを解析して過去ログかどうかを返す
|
22
|
+
# @return [Boolean] 過去ログか否か
|
23
|
+
def kako_log?
|
24
|
+
@f_kako_log || parse_dat[1]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
# datのURLを返す
|
29
|
+
# @return [URI] datのURL
|
30
|
+
def dat_url
|
31
|
+
@thre.board.url+'dat/'+(@thread_key+'.dat')
|
32
|
+
end
|
33
|
+
|
34
|
+
# datファイルを取得する
|
35
|
+
# @return [String] 取得したdatファイルの中身
|
36
|
+
def fetch_dat
|
37
|
+
@data || (@data = Simple2ch.fetch dat_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
# datファイルを解析してResを作成する
|
41
|
+
# @return [Array<Res>] 全てのレス
|
42
|
+
def parse_dat
|
43
|
+
res_num = 0
|
44
|
+
tmp = []
|
45
|
+
f_kako_log = false
|
46
|
+
fetch_dat.each_line do |l|
|
47
|
+
res_num += 1
|
48
|
+
begin
|
49
|
+
tmp << Res.parse(res_num, l)
|
50
|
+
rescue KakoLogException
|
51
|
+
f_kako_log = true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
return @reses=tmp, @f_kako_log=f_kako_log
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Simple2ch
|
2
|
+
class Res
|
3
|
+
# @return [Fixnum] レス番号
|
4
|
+
attr_reader :res_num
|
5
|
+
# @return [String] 投稿者名
|
6
|
+
attr_reader :author
|
7
|
+
# @return [String] ID
|
8
|
+
attr_reader :author_id
|
9
|
+
# @return [Time] 書き込み日時
|
10
|
+
attr_reader :date
|
11
|
+
# @return [String] メール欄
|
12
|
+
attr_reader :mail
|
13
|
+
# @return [String] 内容
|
14
|
+
attr_reader :contents
|
15
|
+
|
16
|
+
KAKO_LOG_INFO = '過去ログ ★<><>[過去ログ]<><em>■ このスレッドは過去ログ倉庫に格納されています</em><>'
|
17
|
+
|
18
|
+
#
|
19
|
+
# @param [Fixnum] res_num レス番号
|
20
|
+
# @param [String] author 投稿者名
|
21
|
+
# @param [String] author_id ID
|
22
|
+
# @param [Time] date 書き込み日時
|
23
|
+
# @param [String] mail メール欄
|
24
|
+
# @param [String] contents 内容
|
25
|
+
def initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '')
|
26
|
+
@res_num = res_num
|
27
|
+
@author = author
|
28
|
+
@author_id = author_id
|
29
|
+
@date = date
|
30
|
+
@mail = mail
|
31
|
+
@contents = contents
|
32
|
+
end
|
33
|
+
|
34
|
+
# Datの1行から各項目を分離して、Resオブジェクトを返す
|
35
|
+
# @param [Fixnum] res_num レス番号
|
36
|
+
# @param [String] contents datのデータ1行
|
37
|
+
# @return [Res] 新規Resオブジェクト
|
38
|
+
# @raise [KakoLogException] 過去ログ情報をパースしようとした際に発生
|
39
|
+
def self.parse(res_num, contents)
|
40
|
+
unless contents.strip == KAKO_LOG_INFO
|
41
|
+
self.new res_num, self.parse_dat(contents)
|
42
|
+
else
|
43
|
+
raise KakoLogException
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
# Datの1行から各項目を分離して、Resオブジェクトを返すメソッドの実体
|
49
|
+
# @param [String] dat datのデータ1行
|
50
|
+
# @raise [DatParseException] Datのパースに失敗したときに発生
|
51
|
+
def self.parse_dat(dat)
|
52
|
+
split_date_and_id_regex = /(^\d{4}\/\d{2}\/\d{2}\(.\) \d{2}:\d{2}:\d{2}\.\d{2}) ID:(\S+)$/
|
53
|
+
ret = {}
|
54
|
+
split = dat.split('<>')
|
55
|
+
ret[:author] = split[0]
|
56
|
+
ret[:mail] = split[1]
|
57
|
+
date_and_author_id = split[2]
|
58
|
+
ret[:contents] = split[3].strip!
|
59
|
+
|
60
|
+
date_and_author_id =~ split_date_and_id_regex
|
61
|
+
if !$1 || !$2
|
62
|
+
raise DatParseException
|
63
|
+
end
|
64
|
+
ret[:date] = Time.parse $1
|
65
|
+
ret[:author_id] = $2
|
66
|
+
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Simple2ch
|
2
|
+
class Thre
|
3
|
+
# @return [String] スレッドの名前
|
4
|
+
attr_reader :title
|
5
|
+
# @return [String] スレッドキー(Unix time)
|
6
|
+
attr_reader :thread_key
|
7
|
+
# @return [Fixnum] 返信の数
|
8
|
+
attr_reader :num_of_response
|
9
|
+
# @return [Board] 属する板
|
10
|
+
attr_reader :board
|
11
|
+
|
12
|
+
# @param [Board] board スレッドが属する板情報
|
13
|
+
# @param [String] thread_data 0000000000.dat<>スレッドタイトル (レス数)
|
14
|
+
def initialize(board, thread_data)
|
15
|
+
@board = board
|
16
|
+
thread_data =~ /(\d{10})\.dat<>(.+) \((\d+)\)/
|
17
|
+
@thread_key = $1
|
18
|
+
@title = $2
|
19
|
+
@num_of_response = $3.to_i
|
20
|
+
@reses = nil
|
21
|
+
@f_kako_log = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# Datを解析して、レスを返す
|
25
|
+
# @return [Array<Res>] レスの配列
|
26
|
+
def reses
|
27
|
+
@reses || fetch_dat[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# 過去ログかどうかを返す
|
31
|
+
# @return [Boolean] 過去ログか否か
|
32
|
+
def kako_log?
|
33
|
+
@f_kako_log || fetch_dat[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
# Datを取ってきてレスと過去ログかどうかを返す
|
38
|
+
# @return [Array<Res>] reses レス
|
39
|
+
# @return [Boolean] f_kako_log 過去ログか否か
|
40
|
+
def fetch_dat
|
41
|
+
dat = Dat.new(self)
|
42
|
+
@reses, @f_kako_log = dat.reses, dat.kako_log?
|
43
|
+
dat = nil
|
44
|
+
return @reses, @f_kako_log
|
45
|
+
end
|
46
|
+
|
47
|
+
#TODO: スコアリング
|
48
|
+
end
|
49
|
+
end
|
data/lib/simple2ch.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "simple2ch/version"
|
2
|
+
|
3
|
+
module Simple2ch
|
4
|
+
DEBUG = true
|
5
|
+
|
6
|
+
require 'simple2ch/simple2ch_exception'
|
7
|
+
require 'simple2ch/board'
|
8
|
+
require 'simple2ch/dat'
|
9
|
+
require 'simple2ch/res'
|
10
|
+
require 'simple2ch/thre'
|
11
|
+
require 'net/http'
|
12
|
+
require 'pp' if DEBUG
|
13
|
+
|
14
|
+
def self.root
|
15
|
+
File.dirname __dir__
|
16
|
+
end
|
17
|
+
|
18
|
+
# HTTPでGETする
|
19
|
+
# @param [URI] url URL
|
20
|
+
# @return [String] 取得本文
|
21
|
+
def self.fetch(url)
|
22
|
+
req = Net::HTTP::Get.new(url.path)
|
23
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
24
|
+
http.request(req)
|
25
|
+
}
|
26
|
+
res.body.force_encoding("cp932").encode!('utf-8', :undef => :replace)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#TODO: テストの用意。
|
31
|
+
#TODO: コメントを書いてメソッドを整える。
|
data/simple2ch.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple2ch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple2ch"
|
8
|
+
spec.version = Simple2ch::VERSION
|
9
|
+
spec.authors = ["dogwood008"]
|
10
|
+
spec.email = ["dogwood008+rubygems@gmail.com"]
|
11
|
+
spec.summary = %q{A gem to read 2ch bbs.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/dogwood008/simple2ch"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rspec-core"
|
25
|
+
spec.add_development_dependency 'rspec-its'
|
26
|
+
spec.add_development_dependency 'spork'
|
27
|
+
|
28
|
+
# spec.add_development_dependency 'spring'
|
29
|
+
# spec.add_development_dependency 'zeus'
|
30
|
+
# spec.add_development_dependency 'guard'
|
31
|
+
# spec.add_development_dependency 'guard-rspec'
|
32
|
+
# spec.add_development_dependency 'guard-zeus'
|
33
|
+
end
|