ttsttb 0.0.2 → 0.2.1

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: c64ead79b53e522b03905ca4201eb0ca0aae343dbe1b651403bc59c5eae83faf
4
- data.tar.gz: '03760922b03c8179709651a8a0fe8e8f30c9c6907a9993550f217923bc050cbb'
3
+ metadata.gz: c47b3a5446b1d79df9a55e7e520350d366148e3cd36b3ea42e685d183cb58495
4
+ data.tar.gz: 76c882d413f2c462d25b9343fd16b1d16c7b557ec79e911c9871cc2211a2d928
5
5
  SHA512:
6
- metadata.gz: cced5dc5b6220ea62e8f161ff49ae513cb0a78c40411dc76305db86a3f49f69ef921f8899095492a1ddba141f1cdac71aaffd652ed67602274e3efa7675b0cb1
7
- data.tar.gz: 36567e5174a43ea6878cfe1792eea0fdd9cfdcbeaddf231109fc04b49e2fddc5744891bca2197fc505fc591dd45f8d36852716ce291d88bc987b945fa1ef947b
6
+ metadata.gz: eb5f9e8afb24ab090fce465538d6049efcc7ec2855d461deaf2b2362a30da389713f5ec156b86a999220f21e706b0e44e2e49455b6675f0db8cd9890578ccb8e
7
+ data.tar.gz: 30adf01d45c97ade98b24d5130a5460d8d1182a6e4457c3dcb65a8996695d8ac9dd9f3667eedaa25027396406cfeced5248a0b6fe5a2ef9a0790d1571f38ba52
@@ -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,43 @@
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
38
+ - name: Archive code coverage results
39
+ uses: actions/upload-artifact@v2
40
+ with:
41
+ name: code-coverage-report
42
+ path: coverage/
43
+
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,32 @@
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
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - 'spec/lib/**/*'
32
+
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,70 @@
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
+ docile (1.4.0)
13
+ mini_portile2 (2.6.1)
14
+ nokogiri (1.12.5)
15
+ mini_portile2 (~> 2.6.1)
16
+ racc (~> 1.4)
17
+ parallel (1.21.0)
18
+ parser (3.0.2.0)
19
+ ast (~> 2.4.1)
20
+ racc (1.5.2)
21
+ rainbow (3.0.0)
22
+ rake (13.0.6)
23
+ regexp_parser (2.1.1)
24
+ rexml (3.2.5)
25
+ rspec (3.10.0)
26
+ rspec-core (~> 3.10.0)
27
+ rspec-expectations (~> 3.10.0)
28
+ rspec-mocks (~> 3.10.0)
29
+ rspec-core (3.10.1)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-expectations (3.10.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-mocks (3.10.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-support (3.10.2)
38
+ rubocop (1.22.1)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.0.0.0)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml
44
+ rubocop-ast (>= 1.12.0, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 1.4.0, < 3.0)
47
+ rubocop-ast (1.12.0)
48
+ parser (>= 3.0.1.1)
49
+ ruby-progressbar (1.11.0)
50
+ simplecov (0.21.2)
51
+ docile (~> 1.1)
52
+ simplecov-html (~> 0.11)
53
+ simplecov_json_formatter (~> 0.1)
54
+ simplecov-html (0.12.3)
55
+ simplecov_json_formatter (0.1.3)
56
+ unicode-display_width (2.1.0)
14
57
 
15
58
  PLATFORMS
16
59
  ruby
17
60
 
18
61
  DEPENDENCIES
19
- bundler (~> 1.16)
20
- rake (~> 10.0)
62
+ bundler (~> 2)
63
+ rake (~> 13.0)
64
+ rspec
65
+ rubocop
66
+ simplecov
21
67
  ttsttb!
22
68
 
23
69
  BUNDLED WITH
24
- 1.16.1
70
+ 2.2.16
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,26 @@ 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
+ ### Publis a new version
242
+
243
+ Create a tag to be released and push to the github reopsitory. Github actions workflow proceeds ruby gem publish process.
244
+ ```
245
+ % git switch master
246
+ % vim lib/ttsttb/version.rb
247
+ % git commit lib/ttsttb/version.rb -m 'bump version'
248
+ % git tag <v0.0.0>
249
+ % git push --tags
250
+ ```
251
+
252
+
204
253
  ## Contributing
205
254
 
206
255
  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.2'.freeze
2
+ VERSION = '0.2.1'.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
+ raise 'Old data before 1990/1/1 is not provided.' if date < Date.new(1990, 1, 1)
14
+
15
+ doc = Nokogiri::HTML(html(date))
16
+ scrape(doc)
17
+ end
18
+
19
+ def self.html(date)
20
+ url = format('http://www.murc-kawasesouba.jp/fx/past/index.php?id=%<ymd>s',
21
+ { :ymd => date.strftime('%y%m%d') })
9
22
 
10
- require 'open-uri'
11
- require 'nokogiri'
23
+ URI.open(url, :redirect => false).read.encode('utf-8')
24
+ rescue OpenURI::HTTPRedirect
25
+ url = format('http://www.murc-kawasesouba.jp/fx/past_3month_result.php?y=%<y>s&m=%<m>s&d=%<d>s&c=',
26
+ {
27
+ :y => date.strftime('%Y'),
28
+ :m => date.strftime('%m'),
29
+ :d => date.strftime('%d')
30
+ })
12
31
 
13
- doc = Nokogiri::HTML(open(url, redirect: false))
32
+ URI.open(url, :redirect => false).read.encode('utf-8')
33
+ end
34
+
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,11 @@ 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"
36
+ spec.add_development_dependency 'simplecov'
33
37
 
34
38
  spec.add_runtime_dependency 'nokogiri'
35
39
 
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.2
4
+ version: 0.2.1
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,70 @@ 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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: nokogiri
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +101,12 @@ executables: []
59
101
  extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
104
+ - ".github/workflows/publish.yml"
105
+ - ".github/workflows/ruby.yml"
62
106
  - ".gitignore"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - ".rubocop_todo.yml"
63
110
  - Gemfile
64
111
  - Gemfile.lock
65
112
  - README.md
@@ -81,15 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
128
  requirements:
82
129
  - - ">="
83
130
  - !ruby/object:Gem::Version
84
- version: '0'
131
+ version: '2.7'
85
132
  required_rubygems_version: !ruby/object:Gem::Requirement
86
133
  requirements:
87
134
  - - ">="
88
135
  - !ruby/object:Gem::Version
89
136
  version: '0'
90
137
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.7.6
138
+ rubygems_version: 3.0.3
93
139
  signing_key:
94
140
  specification_version: 4
95
141
  summary: Fetch TTS and TTB corresponding to the date.