simple2ch 0.1.5 → 0.1.6
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 +53 -25
- data/lib/simple2ch/board.rb +19 -17
- data/lib/simple2ch/res.rb +11 -1
- data/lib/simple2ch/thre.rb +15 -0
- data/lib/simple2ch/version.rb +1 -1
- data/lib/simple2ch.rb +89 -7
- data/spec/board_spec.rb +16 -0
- data/spec/simple2ch_spec.rb +28 -0
- data/spec/thre_spec.rb +81 -30
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ec2043f50a5e9ae0b2b036c2d63c8b494774a6
|
4
|
+
data.tar.gz: 55b076ab99e2448569d5a8b0d3fba090a1586305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3812ee2760a1da7e40a353f49bbad985bcd01f42a0a7296f82eb8aa280ea5b663d07909feb7e97d017fbacd4b2883b33e2c7004b7855f041970714c55203cc4
|
7
|
+
data.tar.gz: d39aa7fd4452dd3f8196cdc9e2e0381d6a30761f9855565cee24e7549cd744693dfa8086d95dca7ed723571004b016b9f2c81cb0cf9c29c730a4909602292e37
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# Simple2ch
|
2
|
-
|
3
2
|
2ch Japanese BBS simple reader for Ruby.
|
4
3
|
|
5
4
|
Ruby用の2chの簡易リーダーです。
|
@@ -8,18 +7,17 @@ Ruby用の2chの簡易リーダーです。
|
|
8
7
|
[リファレンス](http://dogwood008.github.io/simple2ch/)
|
9
8
|
|
10
9
|
## 更新内容
|
11
|
-
[v0.1.5]
|
12
|
-
* デバッグ
|
13
|
-
* StandardErrorで例外を捕縛できない問題を修正
|
14
|
-
* DatParseException, NotA2chUrlException発生時に与えられたURLを表示するよう変更
|
15
|
-
* 機能追加
|
16
|
-
* おーぷん2ちゃんねる対応
|
17
10
|
|
18
|
-
[v0.1.
|
19
|
-
*
|
20
|
-
|
21
|
-
*
|
22
|
-
|
11
|
+
* [v0.1.6]
|
12
|
+
* 機能追加
|
13
|
+
* 板一覧の取得に対応
|
14
|
+
* URLからスレの取得に対応
|
15
|
+
* [v0.1.5]
|
16
|
+
* デバッグ
|
17
|
+
* StandardErrorで例外を捕縛できない問題を修正
|
18
|
+
* DatParseException, NotA2chUrlException発生時に与えられたURLを表示するよう変更
|
19
|
+
* 機能追加
|
20
|
+
* おーぷん2ちゃんねる対応
|
23
21
|
|
24
22
|
|
25
23
|
## Installation
|
@@ -37,31 +35,60 @@ Or install it yourself as:
|
|
37
35
|
$ gem install simple2ch
|
38
36
|
|
39
37
|
## Usage
|
40
|
-
|
38
|
+
### 初期化
|
39
|
+
|
41
40
|
```ruby
|
42
41
|
require 'simple2ch'
|
43
42
|
```
|
44
43
|
|
44
|
+
### Simple2ch
|
45
45
|
|
46
|
-
* スレ取得
|
47
46
|
```ruby
|
48
|
-
|
49
|
-
board.thres #=>[#<Simple2ch::Thre>, ..., #<Simple2ch::Thre>]
|
47
|
+
boards = Simple2ch.boards 'http://open2ch.net' #=> [#<Simple2ch::Board>, ..., #<Simple2ch::Board>]
|
50
48
|
```
|
51
49
|
|
52
|
-
|
50
|
+
### Simple2ch::Board
|
53
51
|
```ruby
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
board = boards.find{|b| b.title == 'プログラム'} #=> #<Simple2ch::Board>
|
53
|
+
board.title #=> "プログラム"
|
54
|
+
board.thres #=> [#<Simple2ch::Thre>, ..., #<Simple2ch::Thre>]
|
57
55
|
```
|
58
56
|
|
59
|
-
|
57
|
+
### Simple2ch::Thre
|
58
|
+
|
60
59
|
```ruby
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
thre = board.thres.find{|t| t.title == 'さぁRubyはじめるよ'} #=> #<Simple2ch::Thre>
|
61
|
+
reses = thre.reses #=> [#<Simple2ch::Res>, ..., #<Simple2ch::Res>]
|
62
|
+
```
|
63
|
+
|
64
|
+
#### URLを直接指定して取得
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
thre = Simple2ch::Thre.create_from_url('http://toro.open2ch.net/test/read.cgi/tech/1371956681/l50') #=> #<Simple2ch::Thre>
|
68
|
+
thre.title #=> "さぁRubyはじめるよ"
|
69
|
+
reses = thre.reses
|
70
|
+
```
|
71
|
+
|
72
|
+
#### 板を指定して取得
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
board = Simple2ch::Board.new('ニュー速VIP', 'http://viper.open2ch.net/news4vip/')
|
76
|
+
thres = board.thres #=>[#<Simple2ch::Thre>, ..., #<Simple2ch::Thre>]
|
77
|
+
thre = thres.find{|t| t.title == 'プログラム'}
|
78
|
+
reses = thre.reses
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
### Simple2ch::Res
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
res = reses[0] #=> #<Simple2ch::Res>
|
86
|
+
res.res_num #=> 1
|
87
|
+
res.contents #=> "Ruby覚えたいなぁ"
|
88
|
+
res.author #=> "s"
|
89
|
+
res.author_id #=> "R/Yck7smD"
|
90
|
+
res.date #=> 2013-06-23 12:04:41 +0900
|
91
|
+
res.mail #=> ""
|
65
92
|
```
|
66
93
|
|
67
94
|
|
@@ -72,3 +99,4 @@ res.contents #=> "hoge foo bar"
|
|
72
99
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
74
101
|
5. Create a new Pull Request
|
102
|
+
|
data/lib/simple2ch/board.rb
CHANGED
@@ -12,10 +12,15 @@ module Simple2ch
|
|
12
12
|
|
13
13
|
# @param [String] title 板の名前
|
14
14
|
# @param [String] url 板のURL
|
15
|
-
|
15
|
+
# @option [Boolean] fetch_title 板の名前を自動取得するか
|
16
|
+
def initialize(title, url, fetch_title:nil)
|
16
17
|
@server_name = @board_name = nil
|
17
18
|
@url = validate_url url
|
18
|
-
@title =
|
19
|
+
@title = if fetch_title
|
20
|
+
(b=Simple2ch.boards(url).find{|bb| bb.url.to_s == @url.to_s}) && b.class!=Array ? b.title : nil
|
21
|
+
else
|
22
|
+
title
|
23
|
+
end
|
19
24
|
@thres = []
|
20
25
|
end
|
21
26
|
|
@@ -35,6 +40,12 @@ module Simple2ch
|
|
35
40
|
@f_open2ch && true
|
36
41
|
end
|
37
42
|
|
43
|
+
# 2chタイプ名の取得
|
44
|
+
# @return [Symbol] 2chタイプ名(:net, :sc, :open)
|
45
|
+
def type_of_2ch
|
46
|
+
Simple2ch.type_of_2ch(@url.to_s)
|
47
|
+
end
|
48
|
+
|
38
49
|
private
|
39
50
|
# URLが正しいかバリデーションする
|
40
51
|
# @param [URI] url
|
@@ -42,22 +53,13 @@ module Simple2ch
|
|
42
53
|
# @raise [URI::InvalidURIError] そもそもURLのフォーマットで無いときに発生
|
43
54
|
def validate_url(url)
|
44
55
|
sp_uri = URI.parse url
|
45
|
-
board_url = ''
|
46
|
-
|
47
56
|
if sp_uri.host.index '2ch'
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@server_name = $~[:server_name]
|
55
|
-
@board_name = $~[:board_name]
|
56
|
-
@f_open2ch = ($~[:openflag] rescue false) && !$~[:openflag].empty? && true
|
57
|
-
board_url = URI.parse("http://#{server_name}.#{@f_open2ch ? 'open' : ''}2ch.#{@f_open2ch ? 'net' : 'sc'}/#{board_name}/")
|
58
|
-
else
|
59
|
-
raise NotA2chUrlException, "Given URL :#{url}"
|
60
|
-
end
|
57
|
+
parsed_url = Simple2ch.parse_url(url.to_s)
|
58
|
+
@server_name = parsed_url[:server_name]
|
59
|
+
@board_name = parsed_url[:board_name]
|
60
|
+
@f_open2ch = !(parsed_url[:openflag].to_s.empty?)
|
61
|
+
@tld = parsed_url[:tld]
|
62
|
+
URI.parse("http://#{server_name}.#{parsed_url[:openflag]}2ch.#{@tld}/#{board_name}/")
|
61
63
|
else
|
62
64
|
raise NotA2chUrlException, "Given URL :#{url}"
|
63
65
|
end
|
data/lib/simple2ch/res.rb
CHANGED
@@ -115,7 +115,17 @@ module Simple2ch
|
|
115
115
|
ret[:date] = Time.parse $~[:time]
|
116
116
|
ret[:author_id] = $~[:author_id]
|
117
117
|
else
|
118
|
-
|
118
|
+
if dat.index 'あぼーん'
|
119
|
+
{
|
120
|
+
author: 'あぼーん',
|
121
|
+
mail: 'あぼーん',
|
122
|
+
contents: 'あぼーん',
|
123
|
+
date: 'あぼーん',
|
124
|
+
author_id: 'あぼーん',
|
125
|
+
}
|
126
|
+
else
|
127
|
+
raise DatParseException, "Data didn't match regex. Data:#{date_and_author_id}"
|
128
|
+
end
|
119
129
|
end
|
120
130
|
|
121
131
|
ret
|
data/lib/simple2ch/thre.rb
CHANGED
@@ -36,6 +36,15 @@ module Simple2ch
|
|
36
36
|
self.new board, thread_key, hash
|
37
37
|
end
|
38
38
|
|
39
|
+
# スレのURLからスレオブジェクトを生成して返す
|
40
|
+
# @param [String] url URL
|
41
|
+
# @return [Thre] スレ
|
42
|
+
def self.create_from_url(url)
|
43
|
+
board = Simple2ch::Board.new('', url, fetch_title: true)
|
44
|
+
thread_key = Simple2ch.parse_url(url)[:thread_key]
|
45
|
+
board.thres.find{|t| t.thread_key == thread_key}
|
46
|
+
end
|
47
|
+
|
39
48
|
# Datを解析して、レスを返す
|
40
49
|
# @param [Array<Fixnum>,Fixnum] num_of_reses 取得したいレス番号
|
41
50
|
# @return [Array<Res>] レスの配列
|
@@ -71,6 +80,12 @@ module Simple2ch
|
|
71
80
|
@received_anchors ||= calc_received_anchors
|
72
81
|
end
|
73
82
|
|
83
|
+
# 2chタイプ名の取得
|
84
|
+
# @return [Symbol] 2chタイプ名(:net, :sc, :open)
|
85
|
+
def type_of_2ch
|
86
|
+
@board ? @board.type_of_2ch : nil
|
87
|
+
end
|
88
|
+
|
74
89
|
private
|
75
90
|
# 全てのレスに対し、あるレスへのアンカーが書き込まれているレス番号のハッシュを返す
|
76
91
|
# @return [Hash]{ res_num<Fixnum> => res_nums<Array<Fixnum>> } レス番号のハッシュ
|
data/lib/simple2ch/version.rb
CHANGED
data/lib/simple2ch.rb
CHANGED
@@ -8,7 +8,7 @@ module Simple2ch
|
|
8
8
|
require 'simple2ch/dat'
|
9
9
|
require 'simple2ch/res'
|
10
10
|
require 'simple2ch/thre'
|
11
|
-
require '
|
11
|
+
require 'open-uri'
|
12
12
|
require 'time'
|
13
13
|
require 'charwidth'
|
14
14
|
require 'pp' if DEBUG
|
@@ -17,15 +17,97 @@ module Simple2ch
|
|
17
17
|
File.dirname __dir__
|
18
18
|
end
|
19
19
|
|
20
|
+
# Module variables
|
21
|
+
@@boards = {}
|
22
|
+
|
20
23
|
# HTTPでGETする
|
21
24
|
# @param [URI] url URL
|
25
|
+
# @param [Symbol] site :net, :sc, :openのいずれか.(2ch.net or 2ch.sc or open2ch.net)
|
22
26
|
# @return [String] 取得本文
|
23
|
-
def self.fetch(url)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def self.fetch(url, site=:sc)
|
28
|
+
res = OpenURI.open_uri(url){|text| text.read }
|
29
|
+
case site
|
30
|
+
when :net, :sc
|
31
|
+
res.force_encoding("cp932").encode!('utf-8', :undef => :replace)
|
32
|
+
when :open
|
33
|
+
res.force_encoding("utf-8")
|
34
|
+
else
|
35
|
+
raise RuntimeError, "Invalid type of 2ch was given: #{site}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# bbsmenuのURLが渡されればセットして,板リストを返す
|
40
|
+
# @param [String] bbsmenu_url bbs_menuのURL
|
41
|
+
# @option [Boolean] force_refresh キャッシュを利用せず板リストを再取得する
|
42
|
+
# @return [Array<Simple2ch::Board>] 板リスト
|
43
|
+
def self.boards(bbsmenu_url=nil, force_refresh:nil)
|
44
|
+
if bbsmenu_url
|
45
|
+
bbsmenu_urls = {
|
46
|
+
net: 'http://menu.2ch.net/bbsmenu.html', sc: 'http://2ch.sc/bbsmenu.html', open: 'http://open2ch.net/menu/pc_menu.html'
|
47
|
+
}
|
48
|
+
# http://www.rubular.com/r/u1TJbQAULD
|
49
|
+
board_extract_regex = /<A HREF=http:\/\/(?<subdomain>\w+).(?<openflag>open|)2ch.(?<tld>sc|net)\/(?<board_name>\w+)\/>(?<board_name_ja>.+)<\/A>/
|
50
|
+
type_of_2ch = self.type_of_2ch(bbsmenu_url)
|
51
|
+
|
52
|
+
if force_refresh || (boards=@@boards.fetch(type_of_2ch, [])).size == 0
|
53
|
+
prepared_bbsmenu_url = bbsmenu_urls[type_of_2ch]
|
54
|
+
|
55
|
+
data = nil
|
56
|
+
boards_array = []
|
57
|
+
|
58
|
+
raise RuntimeError, "Failed to fetch #{url}" if (data = fetch(URI.parse(prepared_bbsmenu_url), type_of_2ch)).empty?
|
59
|
+
raise RuntimeError, "Failed to parse #{url}" if (boards_array=data.scan(board_extract_regex).uniq).empty?
|
60
|
+
|
61
|
+
boards_array.each do |b|
|
62
|
+
boards << Simple2ch::Board.new(b[4],"http://#{b[0]}.#{b[1]}2ch.#{b[2]}/#{b[3]}/")
|
63
|
+
end
|
64
|
+
@@boards[type_of_2ch] = boards
|
65
|
+
else
|
66
|
+
@@boards[type_of_2ch]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# 2chのタイプを返す
|
72
|
+
# @param [String] url URL
|
73
|
+
# @return [Symbol] :open or :net or :sc
|
74
|
+
def self.type_of_2ch(url)
|
75
|
+
parsed_url = self.parse_url(url)
|
76
|
+
openflag = parsed_url[:openflag]
|
77
|
+
tld = parsed_url[:tld]
|
78
|
+
if openflag && tld=='net'
|
79
|
+
:open
|
80
|
+
elsif !openflag && tld=='net'
|
81
|
+
:net
|
82
|
+
elsif !openflag && tld=='sc'
|
83
|
+
:sc
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# URLを分解する
|
90
|
+
# @param [String] url URL
|
91
|
+
# @return [Array<String>] 結果(thread_key等が該当無しの場合,nilを返す)
|
92
|
+
# @raise [NotA2chUrlException] 2chのURLでないURLが与えられた際に発生
|
93
|
+
def self.parse_url(url)
|
94
|
+
# http://www.rubular.com/r/h63xdfmQIH
|
95
|
+
case url
|
96
|
+
when /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/test\/read.cgi\/(?<board_name>.+)\/(?<thread_key>[0-9]+)/,
|
97
|
+
/http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/(?<board_name>.+)\/subject\.txt/,
|
98
|
+
/http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch\.(?<tld>net|sc)\/(?<board_name>.+)\//,
|
99
|
+
/http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch\.(?<tld>net|sc)\/(?<board_name>\w+)/,
|
100
|
+
/http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/(.+)\/dat\/(?<thread_key>[0-9]+)\.dat/,
|
101
|
+
/http:\/\/(?:(?<server_name>\w*)\.)?(?<openflag>open)?2ch\.(?<tld>sc|net)/
|
102
|
+
{ server_name: ($~[:server_name] rescue nil),
|
103
|
+
board_name: ($~[:board_name] rescue nil),
|
104
|
+
openflag: ($~[:openflag] rescue nil),
|
105
|
+
tld: $~[:tld],
|
106
|
+
thread_key: ($~[:thread_key] rescue nil)
|
107
|
+
}
|
108
|
+
else
|
109
|
+
raise NotA2chUrlException, "Given URL: #{url}"
|
110
|
+
end
|
29
111
|
end
|
30
112
|
end
|
31
113
|
|
data/spec/board_spec.rb
CHANGED
@@ -14,6 +14,22 @@ describe Simple2ch::Board do
|
|
14
14
|
end
|
15
15
|
let(:board) { Simple2ch::Board.new(title, url[:sc]) }
|
16
16
|
|
17
|
+
describe 'have a type of 2ch' do
|
18
|
+
subject{ Simple2ch::Board.new(title, given_url) }
|
19
|
+
context 'when 2ch.net' do
|
20
|
+
let(:given_url){ url[:net] }
|
21
|
+
its(:type_of_2ch){ is_expected.to eq :net }
|
22
|
+
end
|
23
|
+
context 'when 2ch.sc' do
|
24
|
+
let(:given_url){ url[:sc] }
|
25
|
+
its(:type_of_2ch){ is_expected.to eq :sc }
|
26
|
+
end
|
27
|
+
context 'when open2ch.net' do
|
28
|
+
let(:given_url){ url[:open] }
|
29
|
+
its(:type_of_2ch){ is_expected.to eq :open }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
17
33
|
context 'should get board title' do
|
18
34
|
subject { board.title }
|
19
35
|
it { is_expected.to be_a_kind_of(String) }
|
data/spec/simple2ch_spec.rb
CHANGED
@@ -1,7 +1,35 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
+
RSpec::Matchers.define :have_news4vip do
|
5
|
+
match do |boards|
|
6
|
+
(news4vip = boards.find{|b| b.title == 'ニュー速VIP'}) && news4vip.url.to_s.index('news4vip')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe Simple2ch do
|
11
|
+
describe 'should get board from board list' do
|
12
|
+
let(:board_list_url) { {net: 'http://menu.2ch.net/bbsmenu.html', sc: 'http://2ch.sc/bbsmenu.html', open: 'http://open2ch.net/menu/pc_menu.html' } }
|
13
|
+
shared_examples 'get board list from bbsmenu' do
|
14
|
+
subject{ Simple2ch.boards(bbsmenu_url) }
|
15
|
+
it{ is_expected.not_to be_empty }
|
16
|
+
it{ is_expected.to have_news4vip}
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'from 2ch.net' do
|
20
|
+
let(:bbsmenu_url) { board_list_url[:net] }
|
21
|
+
include_examples 'get board list from bbsmenu'
|
22
|
+
end
|
23
|
+
context 'from 2ch.sc' do
|
24
|
+
let(:bbsmenu_url) { board_list_url[:sc] }
|
25
|
+
include_examples 'get board list from bbsmenu'
|
26
|
+
end
|
27
|
+
context 'from open2ch.net' do
|
28
|
+
let(:bbsmenu_url) { board_list_url[:open] }
|
29
|
+
include_examples 'get board list from bbsmenu'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
context 'should get reses from board url' do
|
6
34
|
before(:all) do
|
7
35
|
board_name = 'ニュー速VIP'
|
data/spec/thre_spec.rb
CHANGED
@@ -2,45 +2,96 @@ require 'rspec'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Simple2ch::Thre do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
describe 'should have title' do
|
10
|
-
subject { thre.title }
|
11
|
-
it { is_expected.to be_a_kind_of(String) }
|
5
|
+
shared_examples 'have specified reses' do
|
6
|
+
subject { thre.reses(specified_reses) }
|
7
|
+
it { is_expected.to be_a_kind_of Array }
|
8
|
+
its(:size) { is_expected.to be == size }
|
12
9
|
end
|
10
|
+
shared_examples 'should be valid' do
|
11
|
+
describe 'should have title' do
|
12
|
+
subject { thre.title }
|
13
|
+
it { is_expected.to be_a_kind_of(String) }
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
describe 'should have thread key' do
|
17
|
+
subject { thre.thread_key }
|
18
|
+
it { is_expected.to be_a_kind_of(String) }
|
19
|
+
it { is_expected.to match /\d{10}/ }
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
describe 'should have numbers of responses' do
|
23
|
+
subject { thre.num_of_response }
|
24
|
+
it { is_expected.to be_a_kind_of(Fixnum) }
|
25
|
+
it { is_expected.to be > 0 }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'should have responses' do
|
29
|
+
subject { thre.reses }
|
30
|
+
it { is_expected.to be_a_kind_of(Array) }
|
31
|
+
it { subject.each { |r| expect(r).to be_a_kind_of(Simple2ch::Res) } }
|
32
|
+
its(:size) { is_expected.to be > 0 }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'should have if Kako log' do
|
36
|
+
subject { thre.kako_log? }
|
37
|
+
it { is_expected.to kako_log }
|
38
|
+
end
|
25
39
|
|
26
|
-
describe 'should have responses' do
|
27
|
-
subject { thre.reses }
|
28
|
-
it { is_expected.to be_a_kind_of(Array) }
|
29
|
-
it { subject.each { |r| expect(r).to be_a_kind_of(Simple2ch::Res) } }
|
30
|
-
its(:size) { is_expected.to be > 0 }
|
31
40
|
end
|
32
41
|
|
33
|
-
describe 'should
|
34
|
-
|
35
|
-
|
42
|
+
describe 'should be created from URL' do
|
43
|
+
shared_examples 'create from URL' do
|
44
|
+
let(:thre) { Simple2ch::Thre.create_from_url(url) }
|
45
|
+
subject{ thre }
|
46
|
+
it{ is_expected.to be_a_kind_of Simple2ch::Thre }
|
47
|
+
its(:board) { is_expected.to be_a_kind_of Simple2ch::Board }
|
48
|
+
its('board.title') { is_expected.not_to be_empty }
|
49
|
+
its(:title){ is_expected.not_to be_empty }
|
50
|
+
include_examples 'should be valid'
|
51
|
+
end
|
52
|
+
context 'from 2ch.net URL' do
|
53
|
+
let(:url) {'http://peace.2ch.net/test/read.cgi/tech/1158807229/l50'}
|
54
|
+
let(:kako_log){ be_falsey }
|
55
|
+
include_examples 'create from URL'
|
56
|
+
end
|
57
|
+
context 'from 2ch.sc URL' do
|
58
|
+
let(:url) {'http://peace.2ch.sc/test/read.cgi/tech/1158807229/l50'}
|
59
|
+
let(:kako_log){ be_falsey }
|
60
|
+
include_examples 'create from URL'
|
61
|
+
end
|
62
|
+
context 'from open2ch.net URL' do
|
63
|
+
let(:url) {'http://toro.open2ch.net/test/read.cgi/tech/1371956681/l50'}
|
64
|
+
let(:kako_log){ be_falsey }
|
65
|
+
include_examples 'create from URL'
|
66
|
+
end
|
36
67
|
end
|
37
68
|
|
38
|
-
describe '
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
69
|
+
describe 'should have a type of 2ch' do
|
70
|
+
subject{ Simple2ch::Thre.new(board, thread_key) }
|
71
|
+
context '2ch.net' do
|
72
|
+
let!(:board){ Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.2ch.net/news4vip/' }
|
73
|
+
let(:thread_key){ board.thres[0].thread_key }
|
74
|
+
its(:type_of_2ch) { is_expected.to eq :net }
|
75
|
+
end
|
76
|
+
context '2ch.sc' do
|
77
|
+
let!(:board){ Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.2ch.sc/news4vip/' }
|
78
|
+
let(:thread_key){ board.thres[0].thread_key }
|
79
|
+
its(:type_of_2ch) { is_expected.to eq :sc }
|
43
80
|
end
|
81
|
+
context '2ch.net' do
|
82
|
+
let!(:board){ Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.open2ch.net/news4vip/' }
|
83
|
+
let(:thread_key){ board.thres[0].thread_key }
|
84
|
+
its(:type_of_2ch) { is_expected.to eq :open }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'is valid' do
|
89
|
+
let(:board) { Simple2ch::Board.new 'ニュース速報(VIP)', 'http://viper.2ch.sc/news4vip/' }
|
90
|
+
let(:dat_data) { '1409796283.dat<>C言語の勉強始めたんだがな (144)' }
|
91
|
+
let(:thre) { Simple2ch::Thre.parse(board, dat_data) }
|
92
|
+
let(:kako_log) { be_truthy }
|
93
|
+
include_examples 'should be valid'
|
94
|
+
|
44
95
|
context 'when without res_num' do
|
45
96
|
let(:size) { 144 }
|
46
97
|
let(:specified_reses) { nil }
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dogwood008
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -152,3 +152,4 @@ test_files:
|
|
152
152
|
- spec/simple2ch_spec.rb
|
153
153
|
- spec/spec_helper.rb
|
154
154
|
- spec/thre_spec.rb
|
155
|
+
has_rdoc:
|