ttsttb 0.0.1 → 0.2.0

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
  SHA256:
3
- metadata.gz: f916b02b86d132784599993ad65e6ca0d5b6497f3fb9718e958186a2ad2f5937
4
- data.tar.gz: 14bcdc784fa817afcc583ffde6a4206b94e7cb42c4dfb4f54a0c2ce4de468af6
3
+ metadata.gz: b74f82a57cd4e66dd567b8e08fcb912f1e15adef10ecb5425c4cc97a1b81c876
4
+ data.tar.gz: 43025df61b33fa229fd2916f4048136b2335821d71cdf26334e6f20be4c13b4f
5
5
  SHA512:
6
- metadata.gz: 6d1d2881696bd9621131bfa5492d639328be05dcc946361b9f7d8a9ed9d37cf56ce32419a82d75e8ae9559807ca3a1cdd0fb77b16fad71b02f5fc346a463589e
7
- data.tar.gz: 7201d447f742941bd7b60b36f9192a159fd1046ab68b4fd5830e723658a1b381ddf6a24668ccd770af8dcf2169aa487d167bd63c1f61db4f4920964a412e03b9
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 ADDED
@@ -0,0 +1,27 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+
6
+ # This configuration was generated by
7
+ # `rubocop --auto-gen-config`
8
+ # on 2018-02-23 11:31:57 +0900 using RuboCop version 0.48.1.
9
+ # The point is for the user to remove these configuration records
10
+ # one by one as the offenses are removed from the code base.
11
+ # Note that changes in the inspected code, or installation of new
12
+ # versions of RuboCop, may require this file to be generated again.
13
+
14
+ # Offense count: 1
15
+ Metrics/AbcSize:
16
+ Max: 26
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
20
+ # URISchemes: http, https
21
+ Layout/LineLength:
22
+ Max: 99
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments.
26
+ Metrics/MethodLength:
27
+ Max: 20
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,128 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-10-11 07:44:37 UTC using RuboCop version 1.22.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle.
12
+ # SupportedStyles: empty_lines, no_empty_lines
13
+ Layout/EmptyLinesAroundBlockBody:
14
+ Exclude:
15
+ - 'ttsttb.gemspec'
16
+
17
+ # Offense count: 1
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
20
+ Layout/ExtraSpacing:
21
+ Exclude:
22
+ - 'ttsttb.gemspec'
23
+
24
+ # Offense count: 1
25
+ # Cop supports --auto-correct.
26
+ Layout/LeadingEmptyLines:
27
+ Exclude:
28
+ - 'ttsttb.gemspec'
29
+
30
+ # Offense count: 1
31
+ # Cop supports --auto-correct.
32
+ # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
33
+ # SupportedStylesForExponentOperator: space, no_space
34
+ Layout/SpaceAroundOperators:
35
+ Exclude:
36
+ - 'ttsttb.gemspec'
37
+
38
+ # Offense count: 1
39
+ # Cop supports --auto-correct.
40
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
41
+ # SupportedStyles: space, no_space
42
+ # SupportedStylesForEmptyBraces: space, no_space
43
+ Layout/SpaceInsideBlockBraces:
44
+ Exclude:
45
+ - 'Gemfile'
46
+
47
+ # Offense count: 1
48
+ # Cop supports --auto-correct.
49
+ # Configuration parameters: EnforcedStyle.
50
+ # SupportedStyles: final_newline, final_blank_line
51
+ Layout/TrailingEmptyLines:
52
+ Exclude:
53
+ - 'main.rb'
54
+
55
+ # Offense count: 1
56
+ # Configuration parameters: AllowComments.
57
+ Lint/EmptyConditionalBody:
58
+ Exclude:
59
+ - 'ttsttb.gemspec'
60
+
61
+ # Offense count: 1
62
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
63
+ # IgnoredMethods: refine
64
+ Metrics/BlockLength:
65
+ Max: 60
66
+
67
+ # Offense count: 1
68
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
69
+ Metrics/MethodLength:
70
+ Max: 18
71
+
72
+ # Offense count: 2
73
+ Security/Open:
74
+ Exclude:
75
+ - 'lib/ttsttb.rb'
76
+
77
+ # Offense count: 1
78
+ # Cop supports --auto-correct.
79
+ Style/ExpandPathArguments:
80
+ Exclude:
81
+ - 'ttsttb.gemspec'
82
+
83
+ # Offense count: 9
84
+ # Cop supports --auto-correct.
85
+ # Configuration parameters: EnforcedStyle.
86
+ # SupportedStyles: always, always_true, never
87
+ Style/FrozenStringLiteralComment:
88
+ Exclude:
89
+ - 'Gemfile'
90
+ - 'Rakefile'
91
+ - 'bin/console'
92
+ - 'lib/ttsttb.rb'
93
+ - 'lib/ttsttb/version.rb'
94
+ - 'main.rb'
95
+ - 'spec/lib/ttsttb_spec.rb'
96
+ - 'spec/spec_helper.rb'
97
+ - 'ttsttb.gemspec'
98
+
99
+ # Offense count: 7
100
+ # Cop supports --auto-correct.
101
+ # Configuration parameters: UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
102
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
103
+ Style/HashSyntax:
104
+ EnforcedStyle: hash_rockets
105
+
106
+ # Offense count: 2
107
+ # Cop supports --auto-correct.
108
+ # Configuration parameters: PreferredDelimiters.
109
+ Style/PercentLiteralDelimiters:
110
+ Exclude:
111
+ - 'ttsttb.gemspec'
112
+
113
+ # Offense count: 2
114
+ # Cop supports --auto-correct.
115
+ Style/RedundantPercentQ:
116
+ Exclude:
117
+ - 'ttsttb.gemspec'
118
+
119
+ # Offense count: 21
120
+ # Cop supports --auto-correct.
121
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
122
+ # SupportedStyles: single_quotes, double_quotes
123
+ Style/StringLiterals:
124
+ Exclude:
125
+ - 'Gemfile'
126
+ - 'Rakefile'
127
+ - 'bin/console'
128
+ - 'ttsttb.gemspec'
data/Gemfile.lock CHANGED
@@ -1,24 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ttsttb (0.0.1)
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.3.0)
11
- nokogiri (1.8.2)
12
- mini_portile2 (~> 2.3.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
- bundler (~> 1.16)
20
- rake (~> 10.0)
55
+ bundler (~> 2)
56
+ rake (~> 13.0)
57
+ rspec
58
+ rubocop
21
59
  ttsttb!
22
60
 
23
61
  BUNDLED WITH
24
- 1.16.1
62
+ 2.2.16
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Ttsttb
1
+ # TTS TTB library
2
+
3
+ [TTS and TTB value of Forex](http://www.murc-kawasesouba.jp/fx/past_3month.php) is provided by MUFG. Major information provider of TTS and TTB is MUFG in Japan but the data is not provided by commonly used data format like CSV and JSON to handle by program for ease.
4
+
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.
2
6
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ttsttb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,165 +24,204 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
27
+ - Common error
28
+ - `find` method throws `OpenURI::HTTPRedirect` exception if data source is not found.
29
+
25
30
  ```ruby
26
- % irb
27
- irb(main):011:0> pp Ttsttb.find(Date.new(2018,1,1)); nil
31
+ % bin/console
32
+ irb(main):001:0> require 'pp'
33
+ true
34
+ irb(main):001:0> require 'date'
35
+ true
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))
28
39
  {"USD"=>
29
40
  {"currency"=>{"en"=>"US Dollar", "ja"=>"米ドル"},
30
41
  "code"=>"USD",
31
- "tts"=>108.52,
32
- "ttb"=>106.52},
42
+ "tts"=>107.73,
43
+ "ttb"=>105.73,
44
+ "ttm"=>160.6},
33
45
  "EUR"=>
34
46
  {"currency"=>{"en"=>"Euro", "ja"=>"ユーロ"},
35
47
  "code"=>"EUR",
36
- "tts"=>133.41,
37
- "ttb"=>130.41},
48
+ "tts"=>131.54,
49
+ "ttb"=>128.54,
50
+ "ttm"=>195.81},
38
51
  "CAD"=>
39
52
  {"currency"=>{"en"=>"Canadian Dollar", "ja"=>"カナダ・ドル"},
40
53
  "code"=>"CAD",
41
- "tts"=>86.23,
42
- "ttb"=>83.03},
54
+ "tts"=>84.71,
55
+ "ttb"=>81.51,
56
+ "ttm"=>125.47},
43
57
  "GBP"=>
44
58
  {"currency"=>{"en"=>"Pound Sterling", "ja"=>"英ポンド"},
45
59
  "code"=>"GBP",
46
- "tts"=>153.49,
47
- "ttb"=>145.49},
60
+ "tts"=>150.75,
61
+ "ttb"=>142.75,
62
+ "ttm"=>222.13},
48
63
  "CHF"=>
49
64
  {"currency"=>{"en"=>"Swiss Franc", "ja"=>"スイス・フラン"},
50
65
  "code"=>"CHF",
51
- "tts"=>115.36,
52
- "ttb"=>113.56},
66
+ "tts"=>113.78,
67
+ "ttb"=>111.98,
68
+ "ttm"=>169.77},
53
69
  "DKK"=>
54
70
  {"currency"=>{"en"=>"Danish Krone", "ja"=>"デンマーク・クローネ"},
55
71
  "code"=>"DKK",
56
- "tts"=>18.01,
57
- "ttb"=>17.41},
72
+ "tts"=>17.76,
73
+ "ttb"=>17.16,
74
+ "ttm"=>26.34},
58
75
  "NOK"=>
59
76
  {"currency"=>{"en"=>"Norwegian Krone", "ja"=>"ノルウェー・クローネ"},
60
77
  "code"=>"NOK",
61
- "tts"=>13.96,
62
- "ttb"=>13.36},
78
+ "tts"=>13.79,
79
+ "ttb"=>13.19,
80
+ "ttm"=>20.39},
63
81
  "SEK"=>
64
82
  {"currency"=>{"en"=>"Swedish Krona", "ja"=>"スウェーデン・クローネ"},
65
83
  "code"=>"SEK",
66
- "tts"=>13.61,
67
- "ttb"=>12.81},
84
+ "tts"=>13.27,
85
+ "ttb"=>12.47,
86
+ "ttm"=>19.51},
68
87
  "AUD"=>
69
88
  {"currency"=>{"en"=>"Australian Dollar", "ja"=>"オーストラリア・ドル"},
70
89
  "code"=>"AUD",
71
- "tts"=>85.83,
72
- "ttb"=>81.83},
90
+ "tts"=>84.6,
91
+ "ttb"=>80.6,
92
+ "ttm"=>124.9},
73
93
  "NZD"=>
74
94
  {"currency"=>{"en"=>"New Zealand Dollar", "ja"=>"ニュージーランド・ドル"},
75
95
  "code"=>"NZD",
76
- "tts"=>80.63,
77
- "ttb"=>76.63},
96
+ "tts"=>78.87,
97
+ "ttb"=>74.87,
98
+ "ttm"=>116.31},
78
99
  "HKD"=>
79
100
  {"currency"=>{"en"=>"Hong Kong Dollar", "ja"=>"香港ドル"},
80
101
  "code"=>"HKD",
81
- "tts"=>14.17,
82
- "ttb"=>13.31},
102
+ "tts"=>14.07,
103
+ "ttb"=>13.21,
104
+ "ttm"=>20.68},
83
105
  "MYR"=>
84
106
  {"currency"=>{"en"=>"Malaysian Ringgit", "ja"=>"マレーシア・リンギット"},
85
107
  "code"=>"MYR",
86
- "tts"=>0.0,
87
- "ttb"=>0.0},
108
+ "tts"=>nil,
109
+ "ttb"=>nil,
110
+ "ttm"=>nil},
88
111
  "SGD"=>
89
112
  {"currency"=>{"en"=>"Singapore Dollar", "ja"=>"シンガポール・ドル"},
90
113
  "code"=>"SGD",
91
- "tts"=>81.96,
92
- "ttb"=>80.3},
114
+ "tts"=>81.3,
115
+ "ttb"=>79.64,
116
+ "ttm"=>121.12},
93
117
  "SAR"=>
94
118
  {"currency"=>{"en"=>"Saudi Riyal", "ja"=>"サウジ・リアル"},
95
119
  "code"=>"SAR",
96
- "tts"=>29.52,
97
- "ttb"=>27.92},
120
+ "tts"=>29.31,
121
+ "ttb"=>27.71,
122
+ "ttm"=>43.17},
98
123
  "AED"=>
99
124
  {"currency"=>{"en"=>"UAE Dirham", "ja"=>"UAEディルハム"},
100
125
  "code"=>"AED",
101
- "tts"=>29.91,
102
- "ttb"=>28.55},
126
+ "tts"=>29.79,
127
+ "ttb"=>28.43,
128
+ "ttm"=>44.01},
103
129
  "CNY"=>
104
130
  {"currency"=>{"en"=>"Yuan Renminbi", "ja"=>"中国・人民元"},
105
131
  "code"=>"CNY",
106
- "tts"=>17.25,
107
- "ttb"=>16.65},
132
+ "tts"=>17.15,
133
+ "ttb"=>16.55,
134
+ "ttm"=>25.43},
108
135
  "THB"=>
109
136
  {"currency"=>{"en"=>"Baht", "ja"=>"タイ・バーツ"},
110
137
  "code"=>"THB",
111
- "tts"=>3.49,
112
- "ttb"=>3.33},
138
+ "tts"=>3.46,
139
+ "ttb"=>3.3,
140
+ "ttm"=>5.11},
113
141
  "INR"=>
114
142
  {"currency"=>{"en"=>"Indian Rupee", "ja"=>"インド・ルピー"},
115
143
  "code"=>"INR",
116
- "tts"=>1.82,
117
- "ttb"=>1.52},
144
+ "tts"=>1.8,
145
+ "ttb"=>1.5,
146
+ "ttm"=>2.55},
118
147
  "PKR"=>
119
148
  {"currency"=>{"en"=>"Pakistan Rupee", "ja"=>"パキスタン・ルピー"},
120
149
  "code"=>"PKR",
121
- "tts"=>1.13,
122
- "ttb"=>0.83},
150
+ "tts"=>1.12,
151
+ "ttb"=>0.82,
152
+ "ttm"=>1.53},
123
153
  "KWD"=>
124
154
  {"currency"=>{"en"=>"Kuwaiti Dinar", "ja"=>"クウェート・ディナール"},
125
155
  "code"=>"KWD",
126
- "tts"=>367.6,
127
- "ttb"=>351.6},
156
+ "tts"=>364.96,
157
+ "ttb"=>348.96,
158
+ "ttm"=>539.44},
128
159
  "QAR"=>
129
160
  {"currency"=>{"en"=>"Qatari Rial", "ja"=>"カタール・リヤル"},
130
161
  "code"=>"QAR",
131
- "tts"=>30.27,
132
- "ttb"=>28.91},
162
+ "tts"=>30.05,
163
+ "ttb"=>28.69,
164
+ "ttm"=>44.4},
133
165
  "IDR"=>
134
166
  {"currency"=>{"en"=>"Indonesia Rupiah", "ja"=>"インドネシア・ルピア"},
135
167
  "code"=>"IDR",
136
- "tts"=>0.91,
137
- "ttb"=>0.67},
168
+ "tts"=>0.9,
169
+ "ttb"=>0.66,
170
+ "ttm"=>1.23},
138
171
  "MXN"=>
139
172
  {"currency"=>{"en"=>"Mexican Peso", "ja"=>"メキシコ・ペソ"},
140
173
  "code"=>"MXN",
141
- "tts"=>6.71,
142
- "ttb"=>4.71},
174
+ "tts"=>6.66,
175
+ "ttb"=>4.66,
176
+ "ttm"=>8.99},
143
177
  "KRW"=>
144
178
  {"currency"=>{"en"=>"Won", "ja"=>"韓国ウォン"},
145
179
  "code"=>"KRW",
146
- "tts"=>10.16,
147
- "ttb"=>9.76},
180
+ "tts"=>10.05,
181
+ "ttb"=>9.65,
182
+ "ttm"=>14.88},
148
183
  "PHP"=>
149
184
  {"currency"=>{"en"=>"Philippine Peso", "ja"=>"フィリピン・ペソ"},
150
185
  "code"=>"PHP",
151
- "tts"=>2.22,
152
- "ttb"=>1.94},
186
+ "tts"=>2.21,
187
+ "ttb"=>1.93,
188
+ "ttm"=>3.18},
153
189
  "ZAR"=>
154
190
  {"currency"=>{"en"=>"Rand", "ja"=>"南アフリカ・ランド"},
155
191
  "code"=>"ZAR",
156
- "tts"=>10.71,
157
- "ttb"=>7.71},
192
+ "tts"=>10.55,
193
+ "ttb"=>7.55,
194
+ "ttm"=>14.33},
158
195
  "CZK"=>
159
196
  {"currency"=>{"en"=>"Czech Koruna", "ja"=>"チェコ・コルナ"},
160
197
  "code"=>"CZK",
161
- "tts"=>5.33,
162
- "ttb"=>5.09},
198
+ "tts"=>5.24,
199
+ "ttb"=>5.0,
200
+ "ttm"=>7.74},
163
201
  "RUB"=>
164
202
  {"currency"=>{"en"=>"Russian Ruble", "ja"=>"ロシア・ルーブル"},
165
203
  "code"=>"RUB",
166
- "tts"=>2.14,
167
- "ttb"=>1.64},
204
+ "tts"=>2.15,
205
+ "ttb"=>1.65,
206
+ "ttm"=>2.98},
168
207
  "HUF"=>
169
208
  {"currency"=>{"en"=>"Hungarian Forint", "ja"=>"ハンガリー・フォリント"},
170
209
  "code"=>"HUF",
171
- "tts"=>0.44,
172
- "ttb"=>0.4},
210
+ "tts"=>0.43,
211
+ "ttb"=>0.39,
212
+ "ttm"=>0.63},
173
213
  "PLN"=>
174
214
  {"currency"=>{"en"=>"Polish Zloty", "ja"=>"ポーランド・ズロチ"},
175
215
  "code"=>"PLN",
176
- "tts"=>32.77,
177
- "ttb"=>30.37},
216
+ "tts"=>32.35,
217
+ "ttb"=>29.95,
218
+ "ttm"=>47.33},
178
219
  "TRY"=>
179
220
  {"currency"=>{"en"=>"Turkish Lira", "ja"=>"トルコ・リラ"},
180
221
  "code"=>"TRY",
181
- "tts"=>30.83,
182
- "ttb"=>25.83}}
183
- => nil
222
+ "tts"=>30.56,
223
+ "ttb"=>25.56,
224
+ "ttm"=>43.34}}
184
225
  ```
185
226
 
186
227
  ## Development
@@ -189,6 +230,15 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
189
230
 
190
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).
191
232
 
233
+
234
+ ## Tests
235
+
236
+
237
+ ```
238
+ % bundle exec rspec
239
+ ```
240
+
241
+
192
242
  ## Contributing
193
243
 
194
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.0.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/ttsttb.rb CHANGED
@@ -1,32 +1,77 @@
1
1
  require 'ttsttb/version'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'date'
2
5
 
6
+ # Scrape TTS and TTB data from MURC.
3
7
  module Ttsttb
8
+ # Execute scraping
4
9
  def self.find(date)
5
- require 'date'
6
- url = 'http://www.murc-kawasesouba.jp/fx/past/index.php?id=%s' % [date.strftime('%y%m%d')]
10
+ # TODO
11
+ raise 'Today is not supported yet.' if date == Date.today
7
12
 
8
- rows = {}
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
9
20
 
10
- require 'open-uri'
11
- require 'nokogiri'
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
+ })
33
+ end
12
34
 
13
- doc = Nokogiri::HTML(open(url))
35
+ # parse document
36
+ def self.scrape(doc)
37
+ rows = {}
14
38
  doc.xpath('//table[1]/tr').each do |tr|
15
39
  tds = tr.xpath('.//td')
16
40
 
17
41
  next unless tds[0]
18
42
 
43
+ tts = normalize(tds[3].content)
44
+ ttb = normalize(tds[4].content)
45
+
19
46
  rows[tds[2].content] = {
20
47
  'currency' => {
21
48
  'en' => tds[0].content,
22
49
  'ja' => tds[1].content
23
50
  },
24
51
  'code' => tds[2].content,
25
- 'tts' => tds[3].content.strip.to_f,
26
- 'ttb' => tds[4].content.strip.to_f
52
+ 'tts' => tts,
53
+ 'ttb' => ttb,
54
+ 'ttm' => get_ttm(tts, ttb)
27
55
  }
28
56
  end
29
57
 
30
58
  rows
31
59
  end
60
+
61
+ # normalize string to float
62
+ def self.normalize(value)
63
+ value = value.strip
64
+ return nil if value == 'unquoted'
65
+
66
+ value.to_f
67
+ end
68
+
69
+ # calculate TTM
70
+ def self.get_ttm(tts, ttb)
71
+ require 'bigdecimal'
72
+
73
+ return nil unless tts && ttb
74
+
75
+ ((BigDecimal(tts.to_s) + BigDecimal(ttb.to_s)) / 2).round(2).to_f
76
+ end
32
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
@@ -28,8 +29,10 @@ Gem::Specification.new do |spec|
28
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
30
  spec.require_paths = ["lib"]
30
31
 
31
- spec.add_development_dependency "bundler", "~> 1.16"
32
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "bundler", "~> 2"
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.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Matsukura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-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
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
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,12 @@ 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"
94
+ - ".rubocop.yml"
95
+ - ".rubocop_todo.yml"
63
96
  - Gemfile
64
97
  - Gemfile.lock
65
98
  - README.md
@@ -81,15 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
114
  requirements:
82
115
  - - ">="
83
116
  - !ruby/object:Gem::Version
84
- version: '0'
117
+ version: '2.7'
85
118
  required_rubygems_version: !ruby/object:Gem::Requirement
86
119
  requirements:
87
120
  - - ">="
88
121
  - !ruby/object:Gem::Version
89
122
  version: '0'
90
123
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.7.6
124
+ rubygems_version: 3.0.3
93
125
  signing_key:
94
126
  specification_version: 4
95
127
  summary: Fetch TTS and TTB corresponding to the date.