bbs2ch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bbs2ch/board.rb +6 -3
- data/lib/bbs2ch/image.rb +13 -0
- data/lib/bbs2ch/menu.rb +3 -1
- data/lib/bbs2ch/response.rb +19 -3
- data/lib/bbs2ch/thread.rb +9 -6
- data/lib/bbs2ch/version.rb +1 -1
- data/spec/bbs2ch_spec.rb +27 -1
- metadata +3 -3
data/lib/bbs2ch/board.rb
CHANGED
@@ -5,13 +5,16 @@ SUBJECT_FILE = "subject.txt"
|
|
5
5
|
|
6
6
|
module BBS2ch
|
7
7
|
class Board
|
8
|
-
def initialize(name, url)
|
8
|
+
def initialize(name, url, extra = {})
|
9
9
|
@name = name
|
10
10
|
@url = url
|
11
|
+
@extra = extra
|
12
|
+
@extra['board'] = {url: @url, name: @name}
|
11
13
|
end
|
12
14
|
|
13
15
|
# TODO select
|
14
16
|
def threads(regex = /.*/)
|
17
|
+
|
15
18
|
@agent = Mechanize.new
|
16
19
|
page = @agent.get(url + SUBJECT_FILE)
|
17
20
|
|
@@ -19,12 +22,12 @@ module BBS2ch
|
|
19
22
|
page.body.toutf8.lines{|line|
|
20
23
|
th_dat, th_name = line.chomp.split(/<>/)
|
21
24
|
if th_name =~ regex
|
22
|
-
threads << Thread.new(th_name, "#{@url}dat/#{th_dat}")
|
25
|
+
threads << Thread.new(th_name, "#{@url}dat/#{th_dat}", @extra)
|
23
26
|
end
|
24
27
|
}
|
25
28
|
threads
|
26
29
|
end
|
27
30
|
|
28
|
-
attr_accessor :name, :url
|
31
|
+
attr_accessor :name, :url, :extra
|
29
32
|
end
|
30
33
|
end
|
data/lib/bbs2ch/image.rb
CHANGED
data/lib/bbs2ch/menu.rb
CHANGED
@@ -5,10 +5,12 @@ module BBS2ch
|
|
5
5
|
class Menu
|
6
6
|
def initialize(url = nil)
|
7
7
|
@url = url || "http://menu.2ch.net/bbsmenu.html"
|
8
|
+
@extra = {menu: {url: @url}}
|
8
9
|
end
|
9
10
|
|
10
11
|
#TODO select
|
11
12
|
def boards(regex = /.*/)
|
13
|
+
|
12
14
|
@agent = Mechanize.new
|
13
15
|
page = @agent.get url
|
14
16
|
|
@@ -16,7 +18,7 @@ module BBS2ch
|
|
16
18
|
page.links.each{|link|
|
17
19
|
if link.href =~ /[^(www|info)]\.(2ch\.net|bbspink.com|machi\.to|)\//
|
18
20
|
if link.text =~ regex
|
19
|
-
boards << Board.new(link.text, link.href)
|
21
|
+
boards << Board.new(link.text, link.href, @extra)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
}
|
data/lib/bbs2ch/response.rb
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
require 'mechanize'
|
2
|
+
require 'bbs2ch/image'
|
2
3
|
|
3
4
|
module BBS2ch
|
4
5
|
class Response
|
5
|
-
def initialize(
|
6
|
-
@num = num
|
6
|
+
def initialize(name, email, time, message, extra={})
|
7
7
|
@name = name
|
8
8
|
@email = email
|
9
9
|
@time = time
|
10
10
|
@message = message
|
11
|
+
@extra = extra
|
12
|
+
@extra['response'] =
|
13
|
+
{name: @name, email: @email, time: @time, message: @message}
|
11
14
|
end
|
12
15
|
|
13
|
-
|
16
|
+
def images(regex = /((http|https|ttp):\/\/.*\.(jpg|png|gif))/)
|
17
|
+
images = []
|
18
|
+
@message.split(/<br>/).each{|line|
|
19
|
+
match = line.scan regex
|
20
|
+
if match.size > 0
|
21
|
+
url = match[0][0]
|
22
|
+
url = 'h' + url if url[0] != 'h'
|
23
|
+
images << Image.new(url, @extra)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
images
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :name, :email, :time, :message, :extra
|
14
30
|
end
|
15
31
|
end
|
data/lib/bbs2ch/thread.rb
CHANGED
@@ -4,24 +4,27 @@ require 'time'
|
|
4
4
|
|
5
5
|
module BBS2ch
|
6
6
|
class Thread
|
7
|
-
def initialize(name,
|
7
|
+
def initialize(name, url, extra = {})
|
8
8
|
@name = name
|
9
|
-
@
|
9
|
+
@url = url
|
10
|
+
@extra = extra
|
11
|
+
@extra['thread'] = {name: @name, url: @url}
|
10
12
|
end
|
11
13
|
|
12
14
|
# TODO select, cache
|
13
15
|
def responses
|
16
|
+
|
14
17
|
@agent = Mechanize.new
|
15
|
-
page = @agent.get @
|
18
|
+
page = @agent.get @url
|
16
19
|
|
17
20
|
responses = []
|
18
|
-
page.body.toutf8.lines
|
21
|
+
page.body.toutf8.lines{|line|
|
19
22
|
name, email, time_str, message = line.chomp.split(/<>/)
|
20
|
-
responses << Response.new(
|
23
|
+
responses << Response.new(name, email, Time.parse(time_str), message, extra)
|
21
24
|
}
|
22
25
|
responses
|
23
26
|
end
|
24
27
|
|
25
|
-
attr_accessor :name, :
|
28
|
+
attr_accessor :name, :url, :extra
|
26
29
|
end
|
27
30
|
end
|
data/lib/bbs2ch/version.rb
CHANGED
data/spec/bbs2ch_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe BBS2ch do
|
|
30
30
|
|
31
31
|
it 'size not 0' do
|
32
32
|
@menu.boards.size.should_not == 0
|
33
|
-
p @menu.boards(/料理/).first.threads(/料理/).first.responses.first
|
33
|
+
#p @menu.boards(/料理/).first.threads(/料理/).first.responses.first
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -38,8 +38,34 @@ describe BBS2ch do
|
|
38
38
|
|
39
39
|
describe 'Board' do
|
40
40
|
context '#initialize' do
|
41
|
+
end
|
42
|
+
end
|
41
43
|
|
44
|
+
describe 'Thread' do
|
45
|
+
context '#initialize' do
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
describe 'Response' do
|
50
|
+
context '#initialize' do
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#images' do
|
54
|
+
it 'has 2 images' do
|
55
|
+
response = BBS2ch::Response.new('name', 'email', 'time', '
|
56
|
+
http://hoge.com/hoge/piyo.jpg<br>
|
57
|
+
ttp://hoge.com/hoge/piyo.png<br>')
|
58
|
+
images = response.images
|
59
|
+
images[0].url.should == 'http://hoge.com/hoge/piyo.jpg'
|
60
|
+
images[1].url.should == 'http://hoge.com/hoge/piyo.png'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'Image' do
|
66
|
+
context '#initialize' do
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
45
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbs2ch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
segments:
|
97
97
|
- 0
|
98
|
-
hash:
|
98
|
+
hash: 1592949141779228730
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
101
101
|
requirements:
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
segments:
|
106
106
|
- 0
|
107
|
-
hash:
|
107
|
+
hash: 1592949141779228730
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
110
|
rubygems_version: 1.8.24
|