simple2ch 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06540f8c53a91b5a17332526346eb10d30eef3a3
4
- data.tar.gz: 558d933b554ff40333d429139832ff4ea012e07f
3
+ metadata.gz: a768ea004e48d4fd18ae5c19c52646469b7d97b2
4
+ data.tar.gz: 15615e279f263ce11fb4173be0d6cab0aa10d860
5
5
  SHA512:
6
- metadata.gz: a8ecd7d6c4f98653fb177b8591b466c4bd79a5360fa1ae81b849fa2deec149b243fd6eea88f80e2a58763069430705949b73f81aab9b5afa26a72859b9a64c5d
7
- data.tar.gz: 97cafe8a2b0fe8f910cd791e5e3d3976195c438b9a5dba3140835b889e02edcf74292daadb7dfe5712cd717c98e1617572f7cc042d02a20c965542da2bf7fb5c
6
+ metadata.gz: 06123263022a7c964e11198bfc79a25d6c1ddbed030b7e8e1e74b3d89fe6dd491e2566abaa2c18ba122c5d8119b7a71da31ab7624e8f7301a0178a4b6effe543
7
+ data.tar.gz: 83a07323fbf88d98da9e004dbf10e3840bac8e77d598c0e908189d2dc5eb4b403a43d9a2fb3580cb313ca80f3fc02a187d0cc9ee7ce819daaf2c71fd1bf325ee
data/README.md CHANGED
@@ -8,16 +8,19 @@ Ruby用の2chの簡易リーダーです。
8
8
  [リファレンス](http://dogwood008.github.io/simple2ch/)
9
9
 
10
10
  ## 更新内容
11
+ [v0.1.5]
12
+ * デバッグ
13
+ * StandardErrorで例外を捕縛できない問題を修正
14
+ * DatParseException, NotA2chUrlException発生時に与えられたURLを表示するよう変更
15
+ * 機能追加
16
+ * おーぷん2ちゃんねる対応
17
+
11
18
  [v0.1.4]
12
19
  * デバッグ
13
20
  * Thre#resesを実行した際に、IDを持たないレスがあれば、DatParseExceptionが起きる問題を修正
14
21
  * エイリアス追加
15
22
  * Thre#resをThre#resesのエイリアスに設定
16
23
 
17
- [v0.1.3]
18
- * デバッグ
19
- * Res#received_anchors呼び出し時にNoThreGivenExceptionが起きる場合がある問題を修正
20
-
21
24
 
22
25
  ## Installation
23
26
 
data/UPDATES.md CHANGED
@@ -1,3 +1,9 @@
1
+ [v0.1.5]
2
+ * デバッグ
3
+ * StandardErrorで例外を捕縛できない問題を修正
4
+ * 機能追加
5
+ * おーぷん2ちゃんねる対応
6
+
1
7
  [v0.1.4]
2
8
  * デバッグ
3
9
  * Thre#resesを実行した際に、IDを持たないレスがあれば、DatParseExceptionが起きる問題を修正
@@ -29,6 +29,12 @@ module Simple2ch
29
29
  end
30
30
  end
31
31
 
32
+ # おーぷん2chか否かを返す
33
+ # @return [Boolean] おーぷん2chか否か
34
+ def open2ch?
35
+ @f_open2ch && true
36
+ end
37
+
32
38
  private
33
39
  # URLが正しいかバリデーションする
34
40
  # @param [URI] url
@@ -40,18 +46,20 @@ module Simple2ch
40
46
 
41
47
  if sp_uri.host.index '2ch'
42
48
  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}/")
49
+ when /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/test\/read.cgi\/(?<board_name>.+)\/(?<thread_key>[0-9]+)/,
50
+ /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/(?<board_name>.+)\/subject\.txt/,
51
+ /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch\.(?<tld>net|sc)\/(?<board_name>.+)\//,
52
+ /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch\.(?<tld>net|sc)\/(?<board_name>\w+)/,
53
+ /http:\/\/(?<server_name>.+)\.(?<openflag>open)?2ch.(?<tld>net|sc)\/(.+)\/dat\/(?<thread_key>[0-9]+)\.dat/
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}/")
50
58
  else
51
- raise NotA2chUrlException
59
+ raise NotA2chUrlException, "Given URL :#{url}"
52
60
  end
53
61
  else
54
- raise NotA2chUrlException
62
+ raise NotA2chUrlException, "Given URL :#{url}"
55
63
  end
56
64
  end
57
65
 
data/lib/simple2ch/res.rb CHANGED
@@ -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+)$){0,1}/
106
+ split_date_and_id_regex = /(?<time>^\d{4}\/\d{2}\/\d{2}\(.\) ?\d{2}:\d{2}:\d{2}(\.\d{2})?)(?: ID:(?<author_id>\S+)$){0,1}/
107
107
  ret = {}
108
108
  split = dat.split('<>')
109
109
  ret[:author] = split[0]
@@ -111,12 +111,12 @@ module Simple2ch
111
111
  date_and_author_id = split[2]
112
112
  ret[:contents] = split[3].strip
113
113
 
114
- date_and_author_id =~ split_date_and_id_regex
115
- if !$1
116
- raise DatParseException
114
+ if split_date_and_id_regex =~ date_and_author_id
115
+ ret[:date] = Time.parse $~[:time]
116
+ ret[:author_id] = $~[:author_id]
117
+ else
118
+ raise DatParseException, "Data didn't match regex. Data:#{date_and_author_id}"
117
119
  end
118
- ret[:date] = Time.parse $1
119
- ret[:author_id] = $2
120
120
 
121
121
  ret
122
122
  end
@@ -1,5 +1,5 @@
1
1
  module Simple2ch
2
- class Simple2chException < Exception; end
2
+ class Simple2chException < StandardError; end
3
3
  class NotA2chUrlException < Simple2chException; end
4
4
  class KakoLogException < Simple2chException; end
5
5
  class DatParseException < Simple2chException; end
@@ -1,3 +1,3 @@
1
1
  module Simple2ch
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/spec/board_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Simple2ch::Board do
7
7
  {
8
8
  sc: 'http://viper.2ch.sc/news4vip/',
9
9
  net: 'http://viper.2ch.net/news4vip/',
10
- #open: 'http://viper.open2ch.net/news4vip/', #TODO
10
+ open: 'http://viper.open2ch.net/news4vip/',
11
11
  not_a_2ch_format: 'http://test.example.com/hoge/',
12
12
  invalid_url: 'http://abc_def.com/foobar/' # under score in host is invalid
13
13
  }
@@ -33,6 +33,13 @@ describe Simple2ch::Board do
33
33
  its(:size) { is_expected.to be > 0 }
34
34
  end
35
35
 
36
+ context 'should be a valid Simple2ch::Board object' do
37
+ subject { Simple2ch::Board.new(title, url[:open]) }
38
+ its(:title) { is_expected.to be_a_kind_of String }
39
+ its(:title) { is_expected.to be == title }
40
+ its('url.to_s') { is_expected.to be == url[:open] }
41
+ end
42
+
36
43
  context 'should raise NotA2chUrlException if URL is not a 2ch format' do
37
44
  subject { lambda{ Simple2ch::Board.new(title, url[:not_a_2ch_format]) } }
38
45
  it { is_expected.to raise_error Simple2ch::NotA2chUrlException }
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - dogwood008
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2014-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler