eba 1.3.3 → 1.4.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eba/bcb.rb +59 -33
  3. data/lib/eba/version.rb +5 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf8749b76c5de0c62ecf47f0a883a2e8f867106f
4
- data.tar.gz: 4fb8d1d541e15f620474e6de1f1e04531f4c54bf
3
+ metadata.gz: 12867683eab5685d635272ce08a2857c4714adc6
4
+ data.tar.gz: '009c7d7fe4cb54f729406f61cf0351e8cc2d5660'
5
5
  SHA512:
6
- metadata.gz: 18b1a068a9c03f6cf7abd8236cd1606da5bbf8ab15f7faac38fdfc686eb86a8ba8d20f47603d87c89d706641a40a8a1bf2e01479d69e6917a863a868064fd344
7
- data.tar.gz: fd8d96d343bcf6d1970b4cc064cf015f2dd22e30b3c0ba348a24a277ebaa2636e90872fd3299918e22c9a42c5f6ce587de85c37a3adc896276193cfd8743e328
6
+ metadata.gz: 52e3078553a8edfa92b3de8b953fee15715aa2e489a1c9ea7f76e11b64cf5f4f8c7fe6fc34fc7ff969f246a394901163a392ea93629bbd12a80088dd6fcad71d
7
+ data.tar.gz: fe4844fd3f732e39d8f77eb416bf99bfca6e3f1480d17933d3267d15bb99ae44864bc36b99165facd62038b6ba1be7bd59743a0ef4c0a0951c2a8cadb19bcaec
data/lib/eba/bcb.rb CHANGED
@@ -59,6 +59,23 @@ class BCB < Encoder
59
59
  return result
60
60
  end
61
61
 
62
+ def hash_by_periodicity(array_of_codes)
63
+ purged_array_of_codes = purge_invalid_series(array_of_codes)
64
+ result = {}
65
+
66
+ purged_array_of_codes.each do |code|
67
+ dado = get_last_value(code)
68
+
69
+ if not result.key? dado.periodicity then
70
+ result[dado.periodicity] = []
71
+ end
72
+
73
+ result[dado.periodicity] << dado
74
+ end
75
+
76
+ return result
77
+ end
78
+
62
79
  def get_last_value(series_code)
63
80
  begin
64
81
  response = @service.call(:get_ultimo_valor_xml, message: {in0: "#{series_code}"})
@@ -89,7 +106,6 @@ class BCB < Encoder
89
106
  # Ensure that date is in the format dd/MM/YYY
90
107
  def get_all_data_for_array(array_of_codes, date)
91
108
  result = nil
92
- codes = Array.new()
93
109
  data_collection = Array.new()
94
110
 
95
111
  # This request has a limit of series he can get at a time, thus
@@ -98,46 +114,56 @@ class BCB < Encoder
98
114
  # and allow the developer to easily identify which series each data
99
115
  # object pertains.
100
116
  array_of_codes.each_slice(50).to_a.each do |array|
101
- array = purge_invalid_series(array)
117
+ hash = hash_by_periodicity(array)
102
118
 
103
- # Build the message from the start of the historical series
104
- message = { in0: {long: array},
105
- in1: date,
106
- in2: Time.now.strftime('%d/%m/%Y').to_s}
119
+ hash.each do |periodicity, array|
120
+ codes = []
121
+ data_array = []
107
122
 
108
- # try and catch, as some series can be discontinued or a code may be broken
109
- begin
110
- response = @service.call(:get_valores_series_xml, message: message)
111
- result = Nokogiri::XML(response.to_hash[:get_valores_series_xml_response] \
112
- [:get_valores_series_xml_return])
123
+ array.each do |data|
124
+ data_array << data
125
+ codes << data.pk
126
+ end
113
127
 
114
- rescue Exception => erro
115
- puts "Error requesting! #{erro}"
116
- end
128
+ # Build the message from the start of the historical series
129
+ message = { in0: {long: codes},
130
+ in1: date,
131
+ in2: Time.now.strftime('%d/%m/%Y').to_s}
132
+
133
+ # try and catch, as some series can be discontinued or a code may be broken
134
+ begin
135
+ response = @service.call(:get_valores_series_xml, message: message)
136
+ result = Nokogiri::XML(response.to_hash[:get_valores_series_xml_response] \
137
+ [:get_valores_series_xml_return])
138
+
139
+ rescue Exception => erro
140
+ puts "Error requesting! #{erro}"
141
+ end
117
142
 
118
- i = 0
143
+ i = 0
119
144
 
120
- result.css("SERIE").each do |serie|
121
- # recover identifying data from the getLastValue method,
122
- # as the get_valores_series_xml desn't have identifying data
123
- # as series name, periodicity, etc.
124
- base_data = get_last_value(array[i])
125
- comp = 'name="ID" value="' + array[i].to_s + '"'
145
+ result.css("SERIE").each do |serie|
146
+ # recover identifying data from the getLastValue method,
147
+ # as the get_valores_series_xml desn't have identifying data
148
+ # as series name, periodicity, etc.
149
+ base_data = data_array[i]
150
+ comp = 'name="ID" value="' + codes[i].to_s + '"'
126
151
 
127
- if serie.inspect.include? comp
128
- serie.css("ITEM").each do |item|
129
- data_collection << Data_bcb.new(encode(base_data.name),
130
- array[i],
131
- base_data.periodicity,
132
- encode(base_data.unit),
133
- "1",
134
- item.css("DATA").text.split("/")[0],
135
- item.css("DATA").text.split("/")[1],
136
- item.css("VALOR").text)
152
+ if serie.inspect.include? comp
153
+ serie.css("ITEM").each do |item|
154
+ data_collection << Data_bcb.new(encode(base_data.name),
155
+ array[i],
156
+ base_data.periodicity,
157
+ encode(base_data.unit),
158
+ "1",
159
+ item.css("DATA").text.split("/")[0],
160
+ item.css("DATA").text.split("/")[1],
161
+ item.css("VALOR").text)
162
+ end
137
163
  end
138
- end
139
164
 
140
- i = i + 1
165
+ i = i + 1
166
+ end
141
167
  end
142
168
  end
143
169
 
data/lib/eba/version.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Eba
2
2
  # For documentation purposes:
3
3
  # VERSION = mm.dd.ff.hh
4
- # mm - commits on master
4
+ # mm - major change
5
5
  # ff - commits on feature
6
6
  # hh - commits on hotfix
7
7
 
8
- VERSION = "1.3.3"
8
+ VERSION = "1.4.3"
9
9
 
10
10
  #Version 1.0.1
11
11
  #
@@ -33,4 +33,7 @@ module Eba
33
33
 
34
34
  #Version 1.3.3
35
35
  # get_all_data_for_array extracts data now as bulk, in order to make better use of the compression.
36
+
37
+ #Version 1.4.3
38
+ # get_all_data_for_array now handles different periodicities for any ammount of codes.
36
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Campos Cruz