eba 1.4.3 → 1.5.3

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: 12867683eab5685d635272ce08a2857c4714adc6
4
- data.tar.gz: '009c7d7fe4cb54f729406f61cf0351e8cc2d5660'
3
+ metadata.gz: 55af898e71af162b85311da79aa89d7548475f16
4
+ data.tar.gz: 8d4c33a83231025fb5c94b6d70123db580f27619
5
5
  SHA512:
6
- metadata.gz: 52e3078553a8edfa92b3de8b953fee15715aa2e489a1c9ea7f76e11b64cf5f4f8c7fe6fc34fc7ff969f246a394901163a392ea93629bbd12a80088dd6fcad71d
7
- data.tar.gz: fe4844fd3f732e39d8f77eb416bf99bfca6e3f1480d17933d3267d15bb99ae44864bc36b99165facd62038b6ba1be7bd59743a0ef4c0a0951c2a8cadb19bcaec
6
+ metadata.gz: 3451a3d6aadbae4f38a11b7292535ebf52829398a48cf94c26a4faf03df66d114069c8dde10fa6b03288d4e1c8de8c9de493d33eae90bddb72300abc25aeaf1c
7
+ data.tar.gz: 0ad0448c43666985704b8c8337ee07bf0e90ba551257caa0a83e96a650e16ce6262aa04ea29e7178d83e2114136afc221dd7f1ffbf1f437059587c2802ea3064
data/lib/eba/bcb.rb CHANGED
@@ -34,8 +34,8 @@ class BCB < Encoder
34
34
 
35
35
 
36
36
  @service = Savon.client({wsdl: "https://www3.bcb.gov.br/sgspub/JSP/sgsgeral/FachadaWSSGS.wsdl",
37
- ssl_cert_file: @pub_key})#,
38
- #headers: {'Accept-Encoding' => 'gzip, deflate'}})
37
+ ssl_cert_file: @pub_key,
38
+ headers: {'Accept-Encoding' => 'gzip, deflate'}})
39
39
  end
40
40
 
41
41
  # List of all operations available for the webservice,
@@ -76,6 +76,26 @@ class BCB < Encoder
76
76
  return result
77
77
  end
78
78
 
79
+ def build_bcb_data(name, code, periodicity, unit, day, month, year, value)
80
+ encoded_name = encode(name)
81
+ encoded_periodicity = encode(periodicity)
82
+ encoded_unit = encode(unit)
83
+ encoded_day = encode(day)
84
+ encoded_month = encode(month)
85
+ encoded_year = encode(year)
86
+ encoded_value = encode(value)
87
+
88
+ is_unseasoned = name.include? " - com ajuste sazonal"
89
+
90
+ if is_unseasoned then
91
+ name.slice! " - com ajuste sazonal"
92
+ end
93
+
94
+ return Data_bcb.new(encoded_name, code, encoded_periodicity,
95
+ encoded_unit, encoded_day, encoded_month,
96
+ encoded_year, encoded_value, is_unseasoned)
97
+ end
98
+
79
99
  def get_last_value(series_code)
80
100
  begin
81
101
  response = @service.call(:get_ultimo_valor_xml, message: {in0: "#{series_code}"})
@@ -93,14 +113,14 @@ class BCB < Encoder
93
113
  # MES = MONTH
94
114
  # ANO = YEAR
95
115
  # VALOR = VALUE
96
- return Data_bcb.new(encode(xmlResult.search("NOME").text),
97
- series_code,
98
- encode(xmlResult.search("PERIODICIDADE").text),
99
- encode(xmlResult.search("UNIDADE").text),
100
- encode(xmlResult.search("DIA").text),
101
- encode(xmlResult.search("MES").text),
102
- encode(xmlResult.search("ANO").text),
103
- encode(xmlResult.search("VALOR").text))
116
+ return build_bcb_data(xmlResult.search("NOME").text,
117
+ series_code,
118
+ xmlResult.search("PERIODICIDADE").text,
119
+ xmlResult.search("UNIDADE").text,
120
+ xmlResult.search("DIA").text,
121
+ xmlResult.search("MES").text,
122
+ xmlResult.search("ANO").text,
123
+ xmlResult.search("VALOR").text)
104
124
  end
105
125
 
106
126
  # Ensure that date is in the format dd/MM/YYY
@@ -151,14 +171,26 @@ class BCB < Encoder
151
171
 
152
172
  if serie.inspect.include? comp
153
173
  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)
174
+ dia = "1"
175
+ mes = "1"
176
+ ano = "1"
177
+ data = item.css("DATA").text.split("/")
178
+
179
+ if base_data.periodicity == 'D' then
180
+ dia = data[0]
181
+ mes = data[1]
182
+ ano = data[2]
183
+ else
184
+ mes = data[0]
185
+ ano = data[1]
186
+ end
187
+
188
+ data_collection << build_bcb_data(base_data.name,
189
+ array[i],
190
+ base_data.periodicity,
191
+ base_data.unit,
192
+ dia, mes, ano,
193
+ item.css("VALOR").text)
162
194
  end
163
195
  end
164
196
 
data/lib/eba/data.rb CHANGED
@@ -8,11 +8,12 @@ class Data_bcb
8
8
  @date = ""
9
9
  @value = 0.0
10
10
  @pk = 0
11
+ @seasonally_adjusted = false
11
12
 
12
13
  # Initialization is expected to express the state of a single row of
13
14
  # data inside the BCB's Database.
14
15
  def initialize(series_name, series_code, series_periodicity, series_unit,
15
- series_day, series_month, series_year, series_value)
16
+ series_day, series_month, series_year, series_value, seasonally_adjusted)
16
17
 
17
18
  @name = series_name
18
19
  @pk = series_code
@@ -20,6 +21,7 @@ class Data_bcb
20
21
  @unit = series_unit
21
22
  @date = standardizes_date(series_day, series_month, series_year)
22
23
  @value = series_value.to_f
24
+ @seasonally_adjusted = seasonally_adjusted
23
25
  end
24
26
 
25
27
  # Return an "identification key" with data which should
@@ -56,6 +58,10 @@ class Data_bcb
56
58
  return @value
57
59
  end
58
60
 
61
+ def seasonally_adjusted
62
+ return @seasonally_adjusted
63
+ end
64
+
59
65
  # The Webservice will always supply the date in three separate fields,
60
66
  # this methods aim to convert it to a standard dd.mm.YYYY string.
61
67
  def standardizes_date(day, month, year)
@@ -73,7 +79,11 @@ class Data_bcb
73
79
  end
74
80
 
75
81
  def print()
76
- return "Name: #{@name}\nBCB Code: #{@pk}\nPeriodicity: #{@periodicity}\nUnit: #{@unit}\nDate: #{@date} Value: #{@value}\n"
82
+ return "Name: #{@name}\n" +
83
+ "BCB Code: #{@pk}\n" +
84
+ "Periodicity: #{@periodicity}\n" +
85
+ "Unit: #{@unit} Seasonally Adjusted? #{@seasonally_adjusted ? 'YES' : 'NO'}\n" +
86
+ "Date: #{@date} Value: #{@value}\n"
77
87
  end
78
88
 
79
89
  # Simple comparission between two DataBCB objects.
@@ -81,6 +91,6 @@ class Data_bcb
81
91
  return (@name == data_bcb.name and @pk == data_bcb.pk \
82
92
  and @periodicity == data_bcb.periodicity \
83
93
  and @unit == data_bcb.unit and @date == data_bcb.date \
84
- and @value = data_bcb.value)
94
+ and @value = data_bcb.value and @seasonally_adjusted == data_bcb.seasonally_adjusted)
85
95
  end
86
96
  end
data/lib/eba/version.rb CHANGED
@@ -5,7 +5,7 @@ module Eba
5
5
  # ff - commits on feature
6
6
  # hh - commits on hotfix
7
7
 
8
- VERSION = "1.4.3"
8
+ VERSION = "1.5.3"
9
9
 
10
10
  #Version 1.0.1
11
11
  #
@@ -36,4 +36,8 @@ module Eba
36
36
 
37
37
  #Version 1.4.3
38
38
  # get_all_data_for_array now handles different periodicities for any ammount of codes.
39
+
40
+ #Version 1.5.3
41
+ # adds flag in data to mark seasonally adjusted data
42
+ # adds detection for seasonally adjusted data
39
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Campos Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler