bbs_2ch_url_validator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/bbs_2ch_url_validator.rb +47 -1
- data/lib/bbs_2ch_url_validator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6032a83d9f562c5afdfa0833d0f922ba699be031
|
4
|
+
data.tar.gz: 997d6c8e2c5caf3e04b669d56f6cac376cbb13ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d129ed3cdccdf60543b65531ebcf72d4dfb789ba6822fbebfcf5bcf9e249f63796126c6e7187bbaac65941333c1d28a58fd056b9990103f59bb0f9f547569de
|
7
|
+
data.tar.gz: 95fffb701803db771e6387a1c4a8cd7979ab93facfd1c9f7bd0e2b065b2de8fcbc6a727eee2c5c0d99bbb5ccd41ff1d6b57fb3de76056a66291e91d7b6b4a81e
|
data/README.md
CHANGED
@@ -39,3 +39,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/dogwoo
|
|
39
39
|
|
40
40
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
41
|
|
42
|
+
## History
|
43
|
+
|
44
|
+
- v0.1.1 Add UrlInfo#build_url
|
45
|
+
- v0.1.0 first release
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require_relative './bbs_2ch_url_validator/version'
|
3
3
|
|
4
4
|
module Bbs2chUrlValidator
|
5
|
-
# http://www.rubular.com/r/
|
5
|
+
# http://www.rubular.com/r/nFpFxFptsZ
|
6
6
|
VALID_2CH_URL_REGEX = %r(^http:\/\/((?<server_name>.+)\.)?(?<is_open>open)?2ch.(?<tld>net|sc)\/?((test\/read\.cgi\/)?(?<board_name>\w+?)\/?((?<thread_key>\d{9,10})\/?)?)?((?<is_dat>dat)\/(?<thread_key2>\d{9,10})\.dat)?((?<is_subject>subject)\.txt)?((?<is_setting>SETTING)\.TXT)?$) # rubocop:disable Metrics/LineLength
|
7
7
|
|
8
8
|
class URL
|
@@ -53,5 +53,51 @@ module Bbs2chUrlValidator
|
|
53
53
|
instance_variable_set("@#{k}", value)
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
def build_url
|
58
|
+
if @is_dat || @is_subject || @is_setting
|
59
|
+
generate_special_url
|
60
|
+
elsif @thread_key
|
61
|
+
# http://viper.2ch.sc/test/read.cgi/news4vip/9990000001/
|
62
|
+
combine_url("/test/read.cgi/#{@board_name}/#{@thread_key}/")
|
63
|
+
elsif @board_name
|
64
|
+
# http://viper.2ch.sc/news4vip/
|
65
|
+
combine_url("/#{@board_name}/")
|
66
|
+
else
|
67
|
+
# http://2ch.sc http://www.2ch.sc
|
68
|
+
combine_url(nil)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def generate_special_url
|
75
|
+
if @is_dat
|
76
|
+
# http://viper.2ch.sc/news4vip/dat/9990000001.dat
|
77
|
+
combine_url("/#{@board_name}/dat/#{@thread_key}.dat")
|
78
|
+
elsif @is_subject
|
79
|
+
# http://viper.2ch.sc/news4vip/subject.txt
|
80
|
+
combine_url("/#{@board_name}/subject.txt")
|
81
|
+
elsif @is_setting
|
82
|
+
# http://viper.2ch.sc/news4vip/SETTING.TXT
|
83
|
+
combine_url("/#{@board_name}/SETTING.TXT")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def combine_url(path)
|
88
|
+
"http://#{generate_host_name}#{path}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def generate_host_name
|
92
|
+
"#{get_subdomain}#{get_2ch_name}.#{@tld}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_subdomain
|
96
|
+
@server_name ? "#{@server_name}." : nil
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_2ch_name
|
100
|
+
@is_open ? 'open2ch' : '2ch'
|
101
|
+
end
|
56
102
|
end
|
57
103
|
end
|