bbs2ch 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bbs2ch.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 fukayatsu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Bbs2ch
2
+
3
+ A gem to read 2ch bbs
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bbs2ch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bbs2ch
18
+
19
+ ## Usage
20
+
21
+ require 'bbs2ch'
22
+
23
+ menu = BBS2ch::Menu.new
24
+
25
+ # all boards on 2ch
26
+ all_boards = menu.boards
27
+
28
+ # or select with name(regex)
29
+ news_boards = menu.boards(/ニュース/)
30
+
31
+
32
+ # all threads on first news_board
33
+ threads = news_boards.first.threads
34
+
35
+ # or select with name(regex)
36
+ threads = news_boards.first.threads(/政治/)
37
+
38
+ # get responses on the thread
39
+ p threads.first.responses
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ Bundler.setup
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc 'run spec'
8
+ Rspec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = ['-c', '-fs']
10
+ end
data/bbs2ch.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bbs2ch/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["fukayatsu"]
6
+ gem.email = ["fukayatsu@gmail.com"]
7
+ gem.description = %q{A gem to read 2ch bbs}
8
+ gem.summary = %q{A gem to read 2ch bbs}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bbs2ch"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BBS2ch::VERSION
17
+
18
+ gem.add_dependency "mechanize"
19
+
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "fakefs"
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'mechanize'
2
+ require 'bbs2ch/thread'
3
+
4
+ SUBJECT_FILE = "subject.txt"
5
+
6
+ module BBS2ch
7
+ class Board
8
+ def initialize(name, url)
9
+ @name = name
10
+ @url = url
11
+ end
12
+
13
+ # TODO select
14
+ def threads(regex = /.*/)
15
+ @agent = Mechanize.new
16
+ page = @agent.get(url + SUBJECT_FILE)
17
+
18
+ threads = []
19
+ page.body.toutf8.lines{|line|
20
+ th_dat, th_name = line.chomp.split(/<>/)
21
+ if th_name =~ regex
22
+ threads << Thread.new(th_name, "#{@url}dat/#{th_dat}")
23
+ end
24
+ }
25
+ threads
26
+ end
27
+
28
+ attr_accessor :name, :url
29
+ end
30
+ end
File without changes
@@ -0,0 +1,28 @@
1
+ require 'mechanize'
2
+ require 'bbs2ch/board'
3
+
4
+ module BBS2ch
5
+ class Menu
6
+ def initialize(url = nil)
7
+ @url = url || "http://menu.2ch.net/bbsmenu.html"
8
+ end
9
+
10
+ #TODO select
11
+ def boards(regex = /.*/)
12
+ @agent = Mechanize.new
13
+ page = @agent.get url
14
+
15
+ boards = []
16
+ page.links.each{|link|
17
+ if link.href =~ /[^(www|info)]\.(2ch\.net|bbspink.com|machi\.to|)\//
18
+ if link.text =~ regex
19
+ boards << Board.new(link.text, link.href)
20
+ end
21
+ end
22
+ }
23
+ boards
24
+ end
25
+
26
+ attr_accessor :url
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ require 'mechanize'
2
+
3
+ module BBS2ch
4
+ class Response
5
+ def initialize(num, name, email, time, message)
6
+ @num = num
7
+ @name = name
8
+ @email = email
9
+ @time = time
10
+ @message = message
11
+ end
12
+
13
+ attr_reader :num, :name, :email, :time, :message
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ require 'mechanize'
2
+ require 'bbs2ch/response'
3
+ require 'time'
4
+
5
+ module BBS2ch
6
+ class Thread
7
+ def initialize(name, dat_url)
8
+ @name = name
9
+ @dat_url = dat_url
10
+ end
11
+
12
+ # TODO select, cache
13
+ def responses
14
+ @agent = Mechanize.new
15
+ page = @agent.get @dat_url
16
+
17
+ responses = []
18
+ page.body.toutf8.lines.with_index{|line, i|
19
+ name, email, time_str, message = line.chomp.split(/<>/)
20
+ responses << Response.new((i+1), name, email, Time.parse(time_str), message)
21
+ }
22
+ responses
23
+ end
24
+
25
+ attr_accessor :name, :dat_url
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module BBS2ch
2
+ VERSION = "0.0.1"
3
+ end
data/lib/bbs2ch.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "bbs2ch/version"
2
+
3
+ require 'bbs2ch/menu'
4
+ require 'bbs2ch/board'
5
+ require 'bbs2ch/thread'
6
+ require 'bbs2ch/response'
7
+ require 'bbs2ch/image'
data/memo.md ADDED
@@ -0,0 +1,8 @@
1
+ 参考:
2
+
3
+ bundlerを使ってrubygem「Tupper」を作る | Kwappa研究開発室
4
+ http://randd.kwappa.net/2012/07/09/450
5
+
6
+ onodes/ruby2ch
7
+ https://github.com/onodes/ruby2ch
8
+
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ # TODO オフラインでもテストできるようにする
4
+
5
+ require 'bundler'
6
+ Bundler.setup(:default, :test)
7
+
8
+ require 'bbs2ch'
9
+
10
+ describe BBS2ch do
11
+
12
+ describe 'Menu' do
13
+
14
+ context '#initialize' do
15
+ it 'default url' do
16
+ menu = BBS2ch::Menu.new
17
+ menu.url.should == "http://menu.2ch.net/bbsmenu.html"
18
+ end
19
+
20
+ it 'custom url' do
21
+ menu = BBS2ch::Menu.new("http://foo.net")
22
+ menu.url.should == 'http://foo.net'
23
+ end
24
+ end
25
+
26
+ context '#boards' do
27
+ before do
28
+ @menu = BBS2ch::Menu.new
29
+ end
30
+
31
+ it 'size not 0' do
32
+ @menu.boards.size.should_not == 0
33
+ p @menu.boards(/料理/).first.threads(/料理/).first.responses.first
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ describe 'Board' do
40
+ context '#initialize' do
41
+
42
+ end
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbs2ch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - fukayatsu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fakefs
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A gem to read 2ch bbs
63
+ email:
64
+ - fukayatsu@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - bbs2ch.gemspec
75
+ - lib/bbs2ch.rb
76
+ - lib/bbs2ch/board.rb
77
+ - lib/bbs2ch/image.rb
78
+ - lib/bbs2ch/menu.rb
79
+ - lib/bbs2ch/response.rb
80
+ - lib/bbs2ch/thread.rb
81
+ - lib/bbs2ch/version.rb
82
+ - memo.md
83
+ - spec/bbs2ch_spec.rb
84
+ homepage: ''
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -1035967627997445160
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -1035967627997445160
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.24
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: A gem to read 2ch bbs
114
+ test_files:
115
+ - spec/bbs2ch_spec.rb