simple2ch 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +6 -11
- data/UPDATES.md +6 -0
- data/lib/simple2ch/res.rb +3 -3
- data/lib/simple2ch/thre.rb +15 -7
- data/lib/simple2ch/version.rb +1 -1
- data/spec/res_spec.rb +17 -7
- data/spec/thre_spec.rb +23 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06540f8c53a91b5a17332526346eb10d30eef3a3
|
4
|
+
data.tar.gz: 558d933b554ff40333d429139832ff4ea012e07f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8ecd7d6c4f98653fb177b8591b466c4bd79a5360fa1ae81b849fa2deec149b243fd6eea88f80e2a58763069430705949b73f81aab9b5afa26a72859b9a64c5d
|
7
|
+
data.tar.gz: 97cafe8a2b0fe8f910cd791e5e3d3976195c438b9a5dba3140835b889e02edcf74292daadb7dfe5712cd717c98e1617572f7cc042d02a20c965542da2bf7fb5c
|
data/README.md
CHANGED
@@ -8,21 +8,16 @@ Ruby用の2chの簡易リーダーです。
|
|
8
8
|
[リファレンス](http://dogwood008.github.io/simple2ch/)
|
9
9
|
|
10
10
|
## 更新内容
|
11
|
+
[v0.1.4]
|
12
|
+
* デバッグ
|
13
|
+
* Thre#resesを実行した際に、IDを持たないレスがあれば、DatParseExceptionが起きる問題を修正
|
14
|
+
* エイリアス追加
|
15
|
+
* Thre#resをThre#resesのエイリアスに設定
|
16
|
+
|
11
17
|
[v0.1.3]
|
12
18
|
* デバッグ
|
13
19
|
* Res#received_anchors呼び出し時にNoThreGivenExceptionが起きる場合がある問題を修正
|
14
20
|
|
15
|
-
[v0.1.2]
|
16
|
-
* リファクタリングとデバッグ
|
17
|
-
* メソッド修正
|
18
|
-
* Thre#reses(Array<Fixnum>)で指定したレス番号のレスを取得
|
19
|
-
* Thre#resesは今まで通り使用可能
|
20
|
-
* メソッド追加
|
21
|
-
* Thre#received_anchors
|
22
|
-
* 全レスについて被レスを返す
|
23
|
-
* Res#received_anchors(Thre)
|
24
|
-
* 自レスへの被レスを返す
|
25
|
-
|
26
21
|
|
27
22
|
## Installation
|
28
23
|
|
data/UPDATES.md
CHANGED
data/lib/simple2ch/res.rb
CHANGED
@@ -74,7 +74,7 @@ module Simple2ch
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# 自レスへのアンカーが書き込まれているレス番号を返す
|
77
|
-
# @return Array<Fixnum> レス番号
|
77
|
+
# @return [Array<Fixnum>] レス番号
|
78
78
|
def received_anchors
|
79
79
|
thre = get_thre
|
80
80
|
received_anchors = thre.received_anchors
|
@@ -103,7 +103,7 @@ module Simple2ch
|
|
103
103
|
# @param [String] dat datのデータ1行
|
104
104
|
# @raise [DatParseException] Datのパースに失敗したときに発生
|
105
105
|
def self.parse_dat(dat)
|
106
|
-
split_date_and_id_regex = /(^\d{4}\/\d{2}\/\d{2}\(.\) \d{2}:\d{2}:\d{2}\.\d{2}) ID:(\S+)
|
106
|
+
split_date_and_id_regex = /(^\d{4}\/\d{2}\/\d{2}\(.\) \d{2}:\d{2}:\d{2}\.\d{2})(?: ID:(\S+)$){0,1}/
|
107
107
|
ret = {}
|
108
108
|
split = dat.split('<>')
|
109
109
|
ret[:author] = split[0]
|
@@ -112,7 +112,7 @@ module Simple2ch
|
|
112
112
|
ret[:contents] = split[3].strip
|
113
113
|
|
114
114
|
date_and_author_id =~ split_date_and_id_regex
|
115
|
-
if !$1
|
115
|
+
if !$1
|
116
116
|
raise DatParseException
|
117
117
|
end
|
118
118
|
ret[:date] = Time.parse $1
|
data/lib/simple2ch/thre.rb
CHANGED
@@ -37,18 +37,26 @@ module Simple2ch
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Datを解析して、レスを返す
|
40
|
-
# @param [Array<Fixnum
|
40
|
+
# @param [Array<Fixnum>,Fixnum] num_of_reses 取得したいレス番号
|
41
41
|
# @return [Array<Res>] レスの配列
|
42
42
|
def reses(num_of_reses=nil)
|
43
43
|
fetch_dat unless @reses
|
44
|
-
|
45
|
-
|
46
|
-
num_of_reses.
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
case num_of_reses
|
45
|
+
when Array
|
46
|
+
if num_of_reses.size > 0
|
47
|
+
@reses.find_all { |r|
|
48
|
+
num_of_reses.index(r.res_num)
|
49
|
+
}
|
50
|
+
else
|
51
|
+
raise 'Blank array was given.'
|
52
|
+
end
|
53
|
+
when Fixnum
|
54
|
+
@reses.find { |r| r.res_num == num_of_reses }
|
55
|
+
when NilClass
|
56
|
+
@reses
|
50
57
|
end
|
51
58
|
end
|
59
|
+
alias_method :res, :reses
|
52
60
|
|
53
61
|
# 過去ログかどうかを返す
|
54
62
|
# @return [Boolean] 過去ログか否か
|
data/lib/simple2ch/version.rb
CHANGED
data/spec/res_spec.rb
CHANGED
@@ -10,31 +10,31 @@ describe Simple2ch::Res do
|
|
10
10
|
以下、\(^o^)/でVIPがお送りします<><>2014/09/04(木) 18:47:41.41 ID:bHgEtoQU0.net<> 思い切り二次創作じゃねえか <br> PS4でやるんだっけ <>} }
|
11
11
|
let(:res) { dat_data.split(/\n/).map.with_index(1) { |d, i| Simple2ch::Res.parse i, d } }
|
12
12
|
|
13
|
-
|
13
|
+
describe 'should have res number' do
|
14
14
|
subject { res[0].res_num }
|
15
15
|
it { is_expected.to be_a_kind_of(Numeric) }
|
16
16
|
it { is_expected.to be > 0 }
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
describe 'should have author' do
|
20
20
|
subject { res[0].author }
|
21
21
|
it { is_expected.to be_a_kind_of(String) }
|
22
22
|
it { is_expected.not_to be eq nil }
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
describe 'should have author_id' do
|
26
26
|
subject { res[0].author_id }
|
27
27
|
it { is_expected.to be_a_kind_of(String) }
|
28
28
|
it { is_expected.not_to be eq nil }
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
describe 'should have contents' do
|
32
32
|
subject { res[0].contents }
|
33
33
|
it { is_expected.to be_a_kind_of(String) }
|
34
34
|
it { is_expected.not_to be eq nil }
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
describe 'should have date' do
|
38
38
|
subject { res[0].date }
|
39
39
|
it { is_expected.to be_a_kind_of(Time) }
|
40
40
|
it { is_expected.not_to be eq nil }
|
@@ -94,6 +94,16 @@ describe Simple2ch::Res do
|
|
94
94
|
let(:anchor) { [] }
|
95
95
|
it_behaves_like 'have valid anchors'
|
96
96
|
end
|
97
|
+
context 'when a thre have both id and non-id reses', force: true do
|
98
|
+
let(:board_name) { 'プログラム技術' }
|
99
|
+
let(:url) { 'http://toro.2ch.sc/tech/' }
|
100
|
+
let(:thread_key) { '1382307475' }
|
101
|
+
let(:board) { Board.new(board_name, url) }
|
102
|
+
let(:thre) { Thre.new(board, thread_key) }
|
103
|
+
subject { thre.reses }
|
104
|
+
it { is_expected.to be_a_kind_of Array }
|
105
|
+
end
|
106
|
+
|
97
107
|
end
|
98
108
|
|
99
109
|
describe '#recepted_anchors' do
|
@@ -103,8 +113,8 @@ describe Simple2ch::Res do
|
|
103
113
|
let(:board) { Board.new board_name, url }
|
104
114
|
let(:thre) { Thre.new board, thread_key }
|
105
115
|
let(:res) { thre.reses([40])[0] }
|
106
|
-
let(:input_thre) { res.thre = thre}
|
107
|
-
subject{ input_thre; res.received_anchors }
|
116
|
+
let(:input_thre) { res.thre = thre }
|
117
|
+
subject { input_thre; res.received_anchors }
|
108
118
|
it { is_expected.to be_a_kind_of Array }
|
109
119
|
its(:size) { is_expected.to be == 4 }
|
110
120
|
it { is_expected.to be == [43, 44, 45, 54] }
|
data/spec/thre_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rspec'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Simple2ch::Thre do
|
5
|
-
let(:board) { Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.2ch.sc/news4vip/'}
|
5
|
+
let(:board) { Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.2ch.sc/news4vip/' }
|
6
6
|
let(:dat_data) { '1409796283.dat<>C言語の勉強始めたんだがな (144)' }
|
7
7
|
let(:thre) { Simple2ch::Thre.parse(board, dat_data) }
|
8
8
|
|
@@ -26,7 +26,7 @@ describe Simple2ch::Thre do
|
|
26
26
|
describe 'should have responses' do
|
27
27
|
subject { thre.reses }
|
28
28
|
it { is_expected.to be_a_kind_of(Array) }
|
29
|
-
it { subject.each{ |r| expect(r).to be_a_kind_of(Simple2ch::Res) } }
|
29
|
+
it { subject.each { |r| expect(r).to be_a_kind_of(Simple2ch::Res) } }
|
30
30
|
its(:size) { is_expected.to be > 0 }
|
31
31
|
end
|
32
32
|
|
@@ -37,23 +37,34 @@ describe Simple2ch::Thre do
|
|
37
37
|
|
38
38
|
describe '#reses' do
|
39
39
|
shared_examples 'have specified reses' do
|
40
|
-
subject{thre.reses(specified_reses)}
|
41
|
-
it{is_expected.to be_a_kind_of Array}
|
42
|
-
its(:size){is_expected.to be == size}
|
40
|
+
subject { thre.reses(specified_reses) }
|
41
|
+
it { is_expected.to be_a_kind_of Array }
|
42
|
+
its(:size) { is_expected.to be == size }
|
43
43
|
end
|
44
44
|
context 'when without res_num' do
|
45
|
-
let(:size){144}
|
46
|
-
let(:specified_reses){nil}
|
45
|
+
let(:size) { 144 }
|
46
|
+
let(:specified_reses) { nil }
|
47
47
|
it_behaves_like 'have specified reses'
|
48
48
|
end
|
49
49
|
|
50
|
-
context 'when with
|
51
|
-
let(:size){3}
|
52
|
-
let(:specified_reses){[1,2,10]}
|
50
|
+
context 'when with res_nums' do
|
51
|
+
let(:size) { 3 }
|
52
|
+
let(:specified_reses) { [1, 2, 10] }
|
53
53
|
it_behaves_like 'have specified reses'
|
54
|
-
it{
|
54
|
+
it {
|
55
55
|
extracted_reses = thre.reses(specified_reses)
|
56
|
-
expect(extracted_reses[2]).to be == thre.reses.find{|r| r.res_num==10}
|
56
|
+
expect(extracted_reses[2]).to be == thre.reses.find { |r| r.res_num==10 }
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when with only a res_num' do
|
61
|
+
let(:size) { 3 }
|
62
|
+
let(:specified_res_num) { 10 }
|
63
|
+
subject { thre.reses(specified_res_num) }
|
64
|
+
it { is_expected.to be_a_kind_of Res }
|
65
|
+
it {
|
66
|
+
extracted_res = thre.reses(specified_res_num)
|
67
|
+
expect(extracted_res).to be == thre.reses.find { |r| r.res_num==specified_res_num }
|
57
68
|
}
|
58
69
|
end
|
59
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple2ch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dogwood008
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|