exchange_rates_nbp 0.1.3 → 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
  SHA1:
3
- metadata.gz: b2cbf32f8bd4fd153daefb850c754fc61826abfc
4
- data.tar.gz: 23727161bc9bb93a99eb9848966ec7f7f392f06b
3
+ metadata.gz: b59e8ebb0499ef9d95c5f48b7d5a34b2a52a66cb
4
+ data.tar.gz: 81b0c6657e0abf4488f8d4d1a4ce72d3b672e21f
5
5
  SHA512:
6
- metadata.gz: f07448151349cdc26fb30d6f5d968c0cc37cb29417d10f89d8d282e8819515a929e4cfa4178ca05656dc440ef3d41a75d754bf4dbc9dd6132caed9b6efec4450
7
- data.tar.gz: b6f1f93a7d37d51a5e465bfd7a4d4059d0fe6834ffcfa8fe4fe5e78dcf657c03da08a4ad85a226effb27ddf1b8926aff5a3776668980b84d7ba3093d5816d2f2
6
+ metadata.gz: fd2aacc64c7b138c1b86aaeea46b5faa425e4f89442db93766002bdf6f6eb9cf5029f913addf0acdce601edccc376338bf1ea3e7d595551f91371fddc044a77b
7
+ data.tar.gz: e8310ba6e0bea570191c4adb77df6dd860b0604e9a6dfa88e5283cbad269a0761acf8ca595624584f7cdc453b8e4bb44eb97800127564acfeb99be700b1717a6
@@ -3,5 +3,15 @@ Style/Documentation:
3
3
 
4
4
  require: rubocop-rspec
5
5
 
6
+ Style/FrozenStringLiteralComment:
7
+ Enabled: false
8
+
6
9
  RSpec/NestedGroups:
7
- MaxNesting: 3
10
+ Max: 3
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - 'Rakefile'
15
+ - '**/*.rake'
16
+ - 'spec/**/*.rb'
17
+ - '**/*.gemspec'
@@ -1,9 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
4
+ - 2.5.0
5
5
  before_install:
6
- - gem install bundler -v 1.11.2
6
+ - gem install bundler -v 1.16.2
7
7
  notifications:
8
8
  email:
9
9
  on_success: never
@@ -1,3 +1,7 @@
1
+ # 0.2.0 / 2018-12-29
2
+
3
+ * Expose `exchange_table_number` and `exchange_table_date`
4
+
1
5
  # 0.1.3 / 2017-01-02
2
6
 
3
7
  * Fix edge case when table for last year isn't published yet
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'exchange_rates_nbp/version'
5
4
 
@@ -22,18 +21,18 @@ Gem::Specification.new do |spec|
22
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
22
  spec.require_paths = ['lib']
24
23
 
24
+ spec.add_runtime_dependency 'colorize'
25
25
  spec.add_runtime_dependency 'http'
26
26
  spec.add_runtime_dependency 'oga'
27
- spec.add_runtime_dependency 'colorize'
28
27
 
29
28
  spec.add_development_dependency 'bundler', '~> 1.11'
29
+ spec.add_development_dependency 'byebug'
30
+ spec.add_development_dependency 'pry'
30
31
  spec.add_development_dependency 'rake', '~> 10.0'
31
32
  spec.add_development_dependency 'rspec', '~> 3.0'
32
33
  spec.add_development_dependency 'rubocop'
33
34
  spec.add_development_dependency 'rubocop-rspec'
34
- spec.add_development_dependency 'pry'
35
35
  spec.add_development_dependency 'timecop'
36
36
  spec.add_development_dependency 'vcr'
37
37
  spec.add_development_dependency 'webmock'
38
- spec.add_development_dependency 'byebug'
39
38
  end
@@ -21,6 +21,19 @@ module ExchangeRatesNBP
21
21
 
22
22
  DEFAULT_TABLE_TYPES = TABLE_TYPES.values.first
23
23
 
24
+ def self.exchange_table_number(date, table = DEFAULT_TABLE_TYPES)
25
+ exchange_table_info(date, table)[:exchange_table_name]
26
+ end
27
+
28
+ def self.exchange_table_date(date, table = DEFAULT_TABLE_TYPES)
29
+ exchange_table_info(date, table)[:publish_date]
30
+ end
31
+
32
+ def self.exchange_table_info(date, table = DEFAULT_TABLE_TYPES)
33
+ table_id = find_table_id(date, table)
34
+ exchange_table_hash(table_id)
35
+ end
36
+
24
37
  def self.exchange_rate(date, currency_code, table = DEFAULT_TABLE_TYPES)
25
38
  exchange_rate_info(date, currency_code, table)[:exchange_rate]
26
39
  end
@@ -42,5 +55,11 @@ module ExchangeRatesNBP
42
55
  .new(table_id)
43
56
  .exchange_rate(currency_code)
44
57
  end
58
+
59
+ def exchange_table_hash(table_id)
60
+ ExchangeRatesNBP::Clients::CurrencyDataSet
61
+ .new(table_id)
62
+ .exchange_table
63
+ end
45
64
  end
46
65
  end
@@ -23,6 +23,12 @@ module ExchangeRatesNBP
23
23
  currency_element_to_hash(xml, doc)
24
24
  end
25
25
 
26
+ def exchange_table
27
+ xml = Oga.parse_xml(data)
28
+
29
+ table_element_to_hash(xml)
30
+ end
31
+
26
32
  private
27
33
 
28
34
  def currency_element_to_hash(xml, doc)
@@ -33,10 +39,21 @@ module ExchangeRatesNBP
33
39
  }
34
40
  end
35
41
 
42
+ def table_element_to_hash(xml)
43
+ {
44
+ publish_date: to_publish_date(xml),
45
+ exchange_table_name: to_exchange_table(xml)
46
+ }
47
+ end
48
+
36
49
  def to_publish_date(xml)
37
50
  Date.parse(xml.css(FIELD_PUBLISH_DATE).text)
38
51
  end
39
52
 
53
+ def to_exchange_table(xml)
54
+ xml.css(FIELD_TABLE_NAME).text
55
+ end
56
+
40
57
  def to_exchange_rate(doc)
41
58
  doc.css(FIELD_AVERAGE_EXCHANGE_RATE).text.tr(',', '.').to_f
42
59
  end
@@ -1,3 +1,3 @@
1
1
  module ExchangeRatesNBP
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange_rates_nbp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Majewski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-01 00:00:00.000000000 Z
11
+ date: 2018-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: http
14
+ name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: oga
28
+ name: http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: colorize
42
+ name: oga
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -67,63 +67,63 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.11'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '3.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rubocop
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '10.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '10.0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rubocop-rspec
112
+ name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '3.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '3.0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: pry
126
+ name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: timecop
140
+ name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: vcr
154
+ name: timecop
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: webmock
168
+ name: vcr
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,7 +179,7 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: byebug
182
+ name: webmock
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  version: '0'
239
239
  requirements: []
240
240
  rubyforge_project:
241
- rubygems_version: 2.5.1
241
+ rubygems_version: 2.6.14.1
242
242
  signing_key:
243
243
  specification_version: 4
244
244
  summary: Collects exchange rates from nbp.pl