bbs_2ch_url_validator 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 851b64071901bad1882b703adb8207fe38a2e96a
4
- data.tar.gz: c00b062c7b5ecf4bac4965ffd8850671c54d3049
3
+ metadata.gz: 6032a83d9f562c5afdfa0833d0f922ba699be031
4
+ data.tar.gz: 997d6c8e2c5caf3e04b669d56f6cac376cbb13ef
5
5
  SHA512:
6
- metadata.gz: a1d9cadba7b2b4103592af6c2886fc35ffe78dff68178cb8b2a983242845a0a43e2c857c53e3deb6e7e43bc1ef76366a7f400602ef73dfd4c2d879436a26e279
7
- data.tar.gz: 3fb0ada68dfb966dedf87379957829ee4657d1cf7dad27500667a937b9a03653aa0db1a13a5f2718e83388f372553f4da24611b0d6c9b47bdc7c29d05a2f8d84
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/cQbzwkui6C
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
@@ -1,3 +1,3 @@
1
1
  module Bbs2chUrlValidator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbs_2ch_url_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dogwood008