ttsttb 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: ac2db7a7805e980a93a2868e5864af404fecec4706c972cc44f5d83d230c6559
4
- data.tar.gz: 261146e374a799bac282bbd9999dd515f626ffa9af78c173876bf74c4ae19fb1
3
+ metadata.gz: b74f82a57cd4e66dd567b8e08fcb912f1e15adef10ecb5425c4cc97a1b81c876
4
+ data.tar.gz: 43025df61b33fa229fd2916f4048136b2335821d71cdf26334e6f20be4c13b4f
5
5
  SHA512:
6
- metadata.gz: e717c568251b48a67140c2d56113d15efeaa53cd447e9efdf301d374235fb526d4b018f3a8e52f5e5850785bf7e9e9a1fd90ac3d7f4993374b62a04261e8dba6
7
- data.tar.gz: 783efa3d89f1e708d4554e0b6521b449cb913af9bf83c96303b0325820b87888fd7b1f87a776051944f7b8f1b1f97bd97fd9030caa59fcd9f3ae946eee0d656e
6
+ metadata.gz: 8760c59576186caebb3367992a0b6bdcb5a1db97fe7315fc62660acaa735ada4afa1cdd4464f457c7047c89855e7127ca2ce1063512e982de09a74cc6bf9fcde
7
+ data.tar.gz: 7e011078efe0470234eb0e90330129e2ae2d71c3459ea89429611ec7a96279d9169812c23101993f5fc4cc0ab4462f3daf23b3829b1a644b268245418f217db0
@@ -0,0 +1,22 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+ tags:
8
+ - v*
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+
16
+ - name: Release Gem
17
+ if: contains(github.ref, 'refs/tags/v')
18
+ uses: cadwallion/publish-rubygems-action@master
19
+ env:
20
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
+ RELEASE_COMMAND: rake release
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run code format test
35
+ run: bundle exec rubocop
36
+ - name: Run tests
37
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -5,4 +5,5 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /spec/examples.txt
8
9
  /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ NewCops: enable
5
+
3
6
  # This configuration was generated by
4
7
  # `rubocop --auto-gen-config`
5
8
  # on 2018-02-23 11:31:57 +0900 using RuboCop version 0.48.1.
@@ -15,10 +18,10 @@ Metrics/AbcSize:
15
18
  # Offense count: 1
16
19
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
17
20
  # URISchemes: http, https
18
- Metrics/LineLength:
21
+ Layout/LineLength:
19
22
  Max: 99
20
23
 
21
24
  # Offense count: 1
22
25
  # Configuration parameters: CountComments.
23
26
  Metrics/MethodLength:
24
- Max: 16
27
+ Max: 20
data/.rubocop_todo.yml CHANGED
@@ -1,18 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-04-22 06:18:26 UTC using RuboCop version 1.10.0.
3
+ # on 2021-10-11 07:44:37 UTC using RuboCop version 1.22.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
13
- Exclude:
14
- - 'ttsttb.gemspec'
15
-
16
9
  # Offense count: 1
17
10
  # Cop supports --auto-correct.
18
11
  # Configuration parameters: EnforcedStyle.
@@ -66,11 +59,17 @@ Lint/EmptyConditionalBody:
66
59
  - 'ttsttb.gemspec'
67
60
 
68
61
  # Offense count: 1
69
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
70
- Metrics/AbcSize:
71
- Max: 27
62
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
63
+ # IgnoredMethods: refine
64
+ Metrics/BlockLength:
65
+ Max: 60
72
66
 
73
67
  # Offense count: 1
68
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
69
+ Metrics/MethodLength:
70
+ Max: 18
71
+
72
+ # Offense count: 2
74
73
  Security/Open:
75
74
  Exclude:
76
75
  - 'lib/ttsttb.rb'
@@ -81,7 +80,7 @@ Style/ExpandPathArguments:
81
80
  Exclude:
82
81
  - 'ttsttb.gemspec'
83
82
 
84
- # Offense count: 7
83
+ # Offense count: 9
85
84
  # Cop supports --auto-correct.
86
85
  # Configuration parameters: EnforcedStyle.
87
86
  # SupportedStyles: always, always_true, never
@@ -93,9 +92,11 @@ Style/FrozenStringLiteralComment:
93
92
  - 'lib/ttsttb.rb'
94
93
  - 'lib/ttsttb/version.rb'
95
94
  - 'main.rb'
95
+ - 'spec/lib/ttsttb_spec.rb'
96
+ - 'spec/spec_helper.rb'
96
97
  - 'ttsttb.gemspec'
97
98
 
98
- # Offense count: 1
99
+ # Offense count: 7
99
100
  # Cop supports --auto-correct.
100
101
  # Configuration parameters: UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
101
102
  # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
@@ -115,7 +116,7 @@ Style/RedundantPercentQ:
115
116
  Exclude:
116
117
  - 'ttsttb.gemspec'
117
118
 
118
- # Offense count: 19
119
+ # Offense count: 21
119
120
  # Cop supports --auto-correct.
120
121
  # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
121
122
  # SupportedStyles: single_quotes, double_quotes
data/Gemfile.lock CHANGED
@@ -1,23 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ttsttb (0.1.0)
4
+ ttsttb (0.2.0)
5
5
  nokogiri
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- mini_portile2 (2.4.0)
11
- nokogiri (1.10.9)
12
- mini_portile2 (~> 2.4.0)
13
- rake (10.5.0)
10
+ ast (2.4.2)
11
+ diff-lcs (1.4.4)
12
+ mini_portile2 (2.6.1)
13
+ nokogiri (1.12.5)
14
+ mini_portile2 (~> 2.6.1)
15
+ racc (~> 1.4)
16
+ parallel (1.21.0)
17
+ parser (3.0.2.0)
18
+ ast (~> 2.4.1)
19
+ racc (1.5.2)
20
+ rainbow (3.0.0)
21
+ rake (13.0.6)
22
+ regexp_parser (2.1.1)
23
+ rexml (3.2.5)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+ rubocop (1.22.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.0.0.0)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml
43
+ rubocop-ast (>= 1.12.0, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.12.0)
47
+ parser (>= 3.0.1.1)
48
+ ruby-progressbar (1.11.0)
49
+ unicode-display_width (2.1.0)
14
50
 
15
51
  PLATFORMS
16
52
  ruby
17
53
 
18
54
  DEPENDENCIES
19
55
  bundler (~> 2)
20
- rake (~> 10.0)
56
+ rake (~> 13.0)
57
+ rspec
58
+ rubocop
21
59
  ttsttb!
22
60
 
23
61
  BUNDLED WITH
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  I created Ruby gem to get the TTS and TTB corresponding to the passed date. You can get hash of currency code key and value of TTS and TTB.
6
6
 
7
- __Caution__ : This library has no test and exception handling is not tested to cover all the source data.
8
7
 
9
8
 
10
9
  ## Installation
@@ -34,165 +33,195 @@ irb(main):001:0> require 'pp'
34
33
  true
35
34
  irb(main):001:0> require 'date'
36
35
  true
37
- irb(main):003:0> pp Ttsttb.find(Date.new(2018, 1, 7))['USD']['tts']
38
- 108.52
39
- irb(main):004:0> pp Ttsttb.find(Date.new(2018, 1, 1)); nil
36
+ irb(main):003:0> pp Ttsttb.find(Date.new(2018, 3, 7))['USD']['tts']
37
+ 106.62
38
+ irb(main):004:0> pp Ttsttb.find(Date.new(2018, 3, 1))
40
39
  {"USD"=>
41
40
  {"currency"=>{"en"=>"US Dollar", "ja"=>"米ドル"},
42
41
  "code"=>"USD",
43
- "tts"=>108.52,
44
- "ttb"=>106.52},
42
+ "tts"=>107.73,
43
+ "ttb"=>105.73,
44
+ "ttm"=>160.6},
45
45
  "EUR"=>
46
46
  {"currency"=>{"en"=>"Euro", "ja"=>"ユーロ"},
47
47
  "code"=>"EUR",
48
- "tts"=>133.41,
49
- "ttb"=>130.41},
48
+ "tts"=>131.54,
49
+ "ttb"=>128.54,
50
+ "ttm"=>195.81},
50
51
  "CAD"=>
51
52
  {"currency"=>{"en"=>"Canadian Dollar", "ja"=>"カナダ・ドル"},
52
53
  "code"=>"CAD",
53
- "tts"=>86.23,
54
- "ttb"=>83.03},
54
+ "tts"=>84.71,
55
+ "ttb"=>81.51,
56
+ "ttm"=>125.47},
55
57
  "GBP"=>
56
58
  {"currency"=>{"en"=>"Pound Sterling", "ja"=>"英ポンド"},
57
59
  "code"=>"GBP",
58
- "tts"=>153.49,
59
- "ttb"=>145.49},
60
+ "tts"=>150.75,
61
+ "ttb"=>142.75,
62
+ "ttm"=>222.13},
60
63
  "CHF"=>
61
64
  {"currency"=>{"en"=>"Swiss Franc", "ja"=>"スイス・フラン"},
62
65
  "code"=>"CHF",
63
- "tts"=>115.36,
64
- "ttb"=>113.56},
66
+ "tts"=>113.78,
67
+ "ttb"=>111.98,
68
+ "ttm"=>169.77},
65
69
  "DKK"=>
66
70
  {"currency"=>{"en"=>"Danish Krone", "ja"=>"デンマーク・クローネ"},
67
71
  "code"=>"DKK",
68
- "tts"=>18.01,
69
- "ttb"=>17.41},
72
+ "tts"=>17.76,
73
+ "ttb"=>17.16,
74
+ "ttm"=>26.34},
70
75
  "NOK"=>
71
76
  {"currency"=>{"en"=>"Norwegian Krone", "ja"=>"ノルウェー・クローネ"},
72
77
  "code"=>"NOK",
73
- "tts"=>13.96,
74
- "ttb"=>13.36},
78
+ "tts"=>13.79,
79
+ "ttb"=>13.19,
80
+ "ttm"=>20.39},
75
81
  "SEK"=>
76
82
  {"currency"=>{"en"=>"Swedish Krona", "ja"=>"スウェーデン・クローネ"},
77
83
  "code"=>"SEK",
78
- "tts"=>13.61,
79
- "ttb"=>12.81},
84
+ "tts"=>13.27,
85
+ "ttb"=>12.47,
86
+ "ttm"=>19.51},
80
87
  "AUD"=>
81
88
  {"currency"=>{"en"=>"Australian Dollar", "ja"=>"オーストラリア・ドル"},
82
89
  "code"=>"AUD",
83
- "tts"=>85.83,
84
- "ttb"=>81.83},
90
+ "tts"=>84.6,
91
+ "ttb"=>80.6,
92
+ "ttm"=>124.9},
85
93
  "NZD"=>
86
94
  {"currency"=>{"en"=>"New Zealand Dollar", "ja"=>"ニュージーランド・ドル"},
87
95
  "code"=>"NZD",
88
- "tts"=>80.63,
89
- "ttb"=>76.63},
96
+ "tts"=>78.87,
97
+ "ttb"=>74.87,
98
+ "ttm"=>116.31},
90
99
  "HKD"=>
91
100
  {"currency"=>{"en"=>"Hong Kong Dollar", "ja"=>"香港ドル"},
92
101
  "code"=>"HKD",
93
- "tts"=>14.17,
94
- "ttb"=>13.31},
102
+ "tts"=>14.07,
103
+ "ttb"=>13.21,
104
+ "ttm"=>20.68},
95
105
  "MYR"=>
96
106
  {"currency"=>{"en"=>"Malaysian Ringgit", "ja"=>"マレーシア・リンギット"},
97
107
  "code"=>"MYR",
98
- "tts"=>0.0,
99
- "ttb"=>0.0},
108
+ "tts"=>nil,
109
+ "ttb"=>nil,
110
+ "ttm"=>nil},
100
111
  "SGD"=>
101
112
  {"currency"=>{"en"=>"Singapore Dollar", "ja"=>"シンガポール・ドル"},
102
113
  "code"=>"SGD",
103
- "tts"=>81.96,
104
- "ttb"=>80.3},
114
+ "tts"=>81.3,
115
+ "ttb"=>79.64,
116
+ "ttm"=>121.12},
105
117
  "SAR"=>
106
118
  {"currency"=>{"en"=>"Saudi Riyal", "ja"=>"サウジ・リアル"},
107
119
  "code"=>"SAR",
108
- "tts"=>29.52,
109
- "ttb"=>27.92},
120
+ "tts"=>29.31,
121
+ "ttb"=>27.71,
122
+ "ttm"=>43.17},
110
123
  "AED"=>
111
124
  {"currency"=>{"en"=>"UAE Dirham", "ja"=>"UAEディルハム"},
112
125
  "code"=>"AED",
113
- "tts"=>29.91,
114
- "ttb"=>28.55},
126
+ "tts"=>29.79,
127
+ "ttb"=>28.43,
128
+ "ttm"=>44.01},
115
129
  "CNY"=>
116
130
  {"currency"=>{"en"=>"Yuan Renminbi", "ja"=>"中国・人民元"},
117
131
  "code"=>"CNY",
118
- "tts"=>17.25,
119
- "ttb"=>16.65},
132
+ "tts"=>17.15,
133
+ "ttb"=>16.55,
134
+ "ttm"=>25.43},
120
135
  "THB"=>
121
136
  {"currency"=>{"en"=>"Baht", "ja"=>"タイ・バーツ"},
122
137
  "code"=>"THB",
123
- "tts"=>3.49,
124
- "ttb"=>3.33},
138
+ "tts"=>3.46,
139
+ "ttb"=>3.3,
140
+ "ttm"=>5.11},
125
141
  "INR"=>
126
142
  {"currency"=>{"en"=>"Indian Rupee", "ja"=>"インド・ルピー"},
127
143
  "code"=>"INR",
128
- "tts"=>1.82,
129
- "ttb"=>1.52},
144
+ "tts"=>1.8,
145
+ "ttb"=>1.5,
146
+ "ttm"=>2.55},
130
147
  "PKR"=>
131
148
  {"currency"=>{"en"=>"Pakistan Rupee", "ja"=>"パキスタン・ルピー"},
132
149
  "code"=>"PKR",
133
- "tts"=>1.13,
134
- "ttb"=>0.83},
150
+ "tts"=>1.12,
151
+ "ttb"=>0.82,
152
+ "ttm"=>1.53},
135
153
  "KWD"=>
136
154
  {"currency"=>{"en"=>"Kuwaiti Dinar", "ja"=>"クウェート・ディナール"},
137
155
  "code"=>"KWD",
138
- "tts"=>367.6,
139
- "ttb"=>351.6},
156
+ "tts"=>364.96,
157
+ "ttb"=>348.96,
158
+ "ttm"=>539.44},
140
159
  "QAR"=>
141
160
  {"currency"=>{"en"=>"Qatari Rial", "ja"=>"カタール・リヤル"},
142
161
  "code"=>"QAR",
143
- "tts"=>30.27,
144
- "ttb"=>28.91},
162
+ "tts"=>30.05,
163
+ "ttb"=>28.69,
164
+ "ttm"=>44.4},
145
165
  "IDR"=>
146
166
  {"currency"=>{"en"=>"Indonesia Rupiah", "ja"=>"インドネシア・ルピア"},
147
167
  "code"=>"IDR",
148
- "tts"=>0.91,
149
- "ttb"=>0.67},
168
+ "tts"=>0.9,
169
+ "ttb"=>0.66,
170
+ "ttm"=>1.23},
150
171
  "MXN"=>
151
172
  {"currency"=>{"en"=>"Mexican Peso", "ja"=>"メキシコ・ペソ"},
152
173
  "code"=>"MXN",
153
- "tts"=>6.71,
154
- "ttb"=>4.71},
174
+ "tts"=>6.66,
175
+ "ttb"=>4.66,
176
+ "ttm"=>8.99},
155
177
  "KRW"=>
156
178
  {"currency"=>{"en"=>"Won", "ja"=>"韓国ウォン"},
157
179
  "code"=>"KRW",
158
- "tts"=>10.16,
159
- "ttb"=>9.76},
180
+ "tts"=>10.05,
181
+ "ttb"=>9.65,
182
+ "ttm"=>14.88},
160
183
  "PHP"=>
161
184
  {"currency"=>{"en"=>"Philippine Peso", "ja"=>"フィリピン・ペソ"},
162
185
  "code"=>"PHP",
163
- "tts"=>2.22,
164
- "ttb"=>1.94},
186
+ "tts"=>2.21,
187
+ "ttb"=>1.93,
188
+ "ttm"=>3.18},
165
189
  "ZAR"=>
166
190
  {"currency"=>{"en"=>"Rand", "ja"=>"南アフリカ・ランド"},
167
191
  "code"=>"ZAR",
168
- "tts"=>10.71,
169
- "ttb"=>7.71},
192
+ "tts"=>10.55,
193
+ "ttb"=>7.55,
194
+ "ttm"=>14.33},
170
195
  "CZK"=>
171
196
  {"currency"=>{"en"=>"Czech Koruna", "ja"=>"チェコ・コルナ"},
172
197
  "code"=>"CZK",
173
- "tts"=>5.33,
174
- "ttb"=>5.09},
198
+ "tts"=>5.24,
199
+ "ttb"=>5.0,
200
+ "ttm"=>7.74},
175
201
  "RUB"=>
176
202
  {"currency"=>{"en"=>"Russian Ruble", "ja"=>"ロシア・ルーブル"},
177
203
  "code"=>"RUB",
178
- "tts"=>2.14,
179
- "ttb"=>1.64},
204
+ "tts"=>2.15,
205
+ "ttb"=>1.65,
206
+ "ttm"=>2.98},
180
207
  "HUF"=>
181
208
  {"currency"=>{"en"=>"Hungarian Forint", "ja"=>"ハンガリー・フォリント"},
182
209
  "code"=>"HUF",
183
- "tts"=>0.44,
184
- "ttb"=>0.4},
210
+ "tts"=>0.43,
211
+ "ttb"=>0.39,
212
+ "ttm"=>0.63},
185
213
  "PLN"=>
186
214
  {"currency"=>{"en"=>"Polish Zloty", "ja"=>"ポーランド・ズロチ"},
187
215
  "code"=>"PLN",
188
- "tts"=>32.77,
189
- "ttb"=>30.37},
216
+ "tts"=>32.35,
217
+ "ttb"=>29.95,
218
+ "ttm"=>47.33},
190
219
  "TRY"=>
191
220
  {"currency"=>{"en"=>"Turkish Lira", "ja"=>"トルコ・リラ"},
192
221
  "code"=>"TRY",
193
- "tts"=>30.83,
194
- "ttb"=>25.83}}
195
- => nil
222
+ "tts"=>30.56,
223
+ "ttb"=>25.56,
224
+ "ttm"=>43.34}}
196
225
  ```
197
226
 
198
227
  ## Development
@@ -201,6 +230,15 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
201
230
 
202
231
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
203
232
 
233
+
234
+ ## Tests
235
+
236
+
237
+ ```
238
+ % bundle exec rspec
239
+ ```
240
+
241
+
204
242
  ## Contributing
205
243
 
206
244
  Bug reports and pull requests are welcome on GitHub at https://github.com/matsubo/ttsttb.
@@ -1,3 +1,3 @@
1
1
  module Ttsttb
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/ttsttb.rb CHANGED
@@ -1,23 +1,35 @@
1
1
  require 'ttsttb/version'
2
2
  require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'date'
3
5
 
4
6
  # Scrape TTS and TTB data from MURC.
5
7
  module Ttsttb
6
8
  # Execute scraping
7
9
  def self.find(date)
8
10
  # TODO
9
- throw 'Data of today is not supported yet.' if date == Date.today
11
+ raise 'Today is not supported yet.' if date == Date.today
10
12
 
11
- # TODO
12
- throw 'Old data is not supported yet.' if date == Date.new(2006, 1, 1)
13
-
14
- require 'date'
15
- url = format('http://www.murc-kawasesouba.jp/fx/past/index.php?id=%s', date.strftime('%y%m%d'))
16
-
17
- require 'open-uri'
13
+ begin
14
+ doc = Nokogiri::HTML(URI.open(url(date), :redirect => false).read.encode('utf-8'))
15
+ scrape(doc)
16
+ rescue OpenURI::HTTPRedirect
17
+ raise 'Data is not found on the MUFG page corresponding to the specificate date.'
18
+ end
19
+ end
18
20
 
19
- doc = Nokogiri::HTML(URI.open(url, :redirect => false))
20
- scrape(doc)
21
+ def self.url(date)
22
+ url = format('http://www.murc-kawasesouba.jp/fx/past/index.php?id=%<ymd>s',
23
+ { :ymd => date.strftime('%y%m%d') })
24
+ URI.open(url, :redirect => false)
25
+ url
26
+ rescue OpenURI::HTTPRedirect
27
+ format('http://www.murc-kawasesouba.jp/fx/past_3month_result.php?y=%<y>s&m=%<m>s&d=%<d>s&c=',
28
+ {
29
+ :y => date.strftime('%Y'),
30
+ :m => date.strftime('%m'),
31
+ :d => date.strftime('%d')
32
+ })
21
33
  end
22
34
 
23
35
  # parse document
@@ -28,15 +40,18 @@ module Ttsttb
28
40
 
29
41
  next unless tds[0]
30
42
 
43
+ tts = normalize(tds[3].content)
44
+ ttb = normalize(tds[4].content)
45
+
31
46
  rows[tds[2].content] = {
32
47
  'currency' => {
33
48
  'en' => tds[0].content,
34
49
  'ja' => tds[1].content
35
50
  },
36
51
  'code' => tds[2].content,
37
- 'tts' => normalize(tds[3].content),
38
- 'ttb' => normalize(tds[4].content),
39
- 'ttm' => get_ttm(normalize(tds[3].content), normalize(tds[4].content))
52
+ 'tts' => tts,
53
+ 'ttb' => ttb,
54
+ 'ttm' => get_ttm(tts, ttb)
40
55
  }
41
56
  end
42
57
 
@@ -57,6 +72,6 @@ module Ttsttb
57
72
 
58
73
  return nil unless tts && ttb
59
74
 
60
- (BigDecimal(tts.to_s) + BigDecimal(ttb.to_s) / 2).round(2).to_f
75
+ ((BigDecimal(tts.to_s) + BigDecimal(ttb.to_s)) / 2).round(2).to_f
61
76
  end
62
77
  end
data/ttsttb.gemspec CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  if spec.respond_to?(:metadata)
19
19
  else
20
20
  raise "RubyGems 2.0 or newer is required to protect against " \
21
- "public gem pushes."
21
+ "public gem pushes."
22
22
  end
23
23
 
24
+ spec.required_ruby_version = '>= 2.7'
24
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
26
  f.match(%r{^(test|spec|features)/})
26
27
  end
@@ -29,7 +30,9 @@ Gem::Specification.new do |spec|
29
30
  spec.require_paths = ["lib"]
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 2"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rspec"
35
+ spec.add_development_dependency "rubocop"
33
36
 
34
37
  spec.add_runtime_dependency 'nokogiri'
35
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttsttb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Matsukura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-22 00:00:00.000000000 Z
11
+ date: 2021-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: nokogiri
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +87,10 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
90
+ - ".github/workflows/publish.yml"
91
+ - ".github/workflows/ruby.yml"
62
92
  - ".gitignore"
93
+ - ".rspec"
63
94
  - ".rubocop.yml"
64
95
  - ".rubocop_todo.yml"
65
96
  - Gemfile
@@ -75,7 +106,7 @@ files:
75
106
  homepage: https://github.com/matsubo/ttsttb
76
107
  licenses: []
77
108
  metadata: {}
78
- post_install_message:
109
+ post_install_message:
79
110
  rdoc_options: []
80
111
  require_paths:
81
112
  - lib
@@ -83,15 +114,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
114
  requirements:
84
115
  - - ">="
85
116
  - !ruby/object:Gem::Version
86
- version: '0'
117
+ version: '2.7'
87
118
  required_rubygems_version: !ruby/object:Gem::Requirement
88
119
  requirements:
89
120
  - - ">="
90
121
  - !ruby/object:Gem::Version
91
122
  version: '0'
92
123
  requirements: []
93
- rubygems_version: 3.1.2
94
- signing_key:
124
+ rubygems_version: 3.0.3
125
+ signing_key:
95
126
  specification_version: 4
96
127
  summary: Fetch TTS and TTB corresponding to the date.
97
128
  test_files: []