Class: Helper

Inherits:
Encoder show all
Defined in:
lib/eba/helper.rb

Direct Known Subclasses

BCB

Instance Method Summary collapse

Methods inherited from Encoder

#encode

Constructor Details

#initializeHelper

Returns a new instance of Helper.



5
6
# File 'lib/eba/helper.rb', line 5

def initialize()
end

Instance Method Details

#build_bcb_data(name, code, periodicity, unit, day, month, year, value, is_unseasoned) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/eba/helper.rb', line 8

def build_bcb_data(name, code, periodicity, unit, day, month, year, value, is_unseasoned)
	if name[" - com ajuste sazonal"] != nil then
		is_unseasoned = true

		if is_unseasoned then
			name.slice!(" - com ajuste sazonal")
		end		
	end

	encoded_name = encode(name)
	encoded_periodicity = encode(periodicity)
	encoded_unit = encode(unit)
	encoded_day = day
	encoded_month = month
	encoded_year = year
	encoded_value = encode(value)
	
	return Data_bcb.new(encoded_name, code, encoded_periodicity,
			    						encoded_unit, encoded_day, encoded_month,
			    						encoded_year, encoded_value, is_unseasoned)
end

#extract_an_item(serie, code, base_data, data_collection) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/eba/helper.rb', line 45

def extract_an_item(serie, code, base_data, data_collection)
	# recover identifying data from the getLastValue method,
	# as the get_valores_series_xml desn't have identifying data
	# as series name, periodicity, etc. 
 
	if serie.inspect["name=\"ID\" value=\"#{code}\""] != nil then
		serie.css("ITEM").each do |item|
			dia = "01"
			mes = "1"
			ano = "1"
			data = item.css("DATA").text.split("/")

			if base_data.periodicity == 'D' then
				dia = data[0]
				mes = data[1]
				ano = data[2]
			else
				mes = data[0]
				ano = data[1]
			end 

			data_collection << build_bcb_data(base_data.name, code, 
																								base_data.periodicity, 
																								base_data.unit, 
																								dia, mes, ano, 
																								item.css("VALOR").text,
																								base_data.seasonally_adjusted)
		end
	end
end

#purge_invalid_series(array_of_codes, hash_last_values) ⇒ Object

Removes all invalid series from an array.

An invalid series has last value.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/eba/helper.rb', line 33

def purge_invalid_series(array_of_codes, hash_last_values)
	result = []

	array_of_codes.each do |code|
		if hash_last_values[code] != nil then
			result << code
		end
	end

	return result 
end