Class: Data_bcb
- Inherits:
-
Object
- Object
- Data_bcb
- Defined in:
- lib/eba/data.rb
Overview
This class intends to organize the series data in a easy to use way, making it easier to group lots of data in a coese way, without lost of information.
Class Method Summary collapse
Instance Method Summary collapse
-
#compare_to(data_bcb) ⇒ Object
Simple comparission between two DataBCB objects.
- #date ⇒ Object
-
#initialize(series_name, series_code, series_periodicity, series_unit, series_day, series_month, series_year, series_value, seasonally_adjusted) ⇒ Data_bcb
constructor
Initialization is expected to express the state of a single row of data inside the BCB’s Database.
- #is_valid? ⇒ Boolean
-
#key ⇒ Object
Return an “identification key” with data which should be unique to a series (grouped).
- #name ⇒ Object
- #periodicity ⇒ Object
-
#pk ⇒ Object
Note that there are no set methods in this class, I built it in such a way that you are only intended to access data in the rawest form as possible as it comes from the BCB Webservice.
- #print ⇒ Object
- #seasonally_adjusted ⇒ Object
-
#standardizes_date(day, month, year) ⇒ Object
The Webservice will always supply the date in three separate fields, this methods aim to convert it to a standard dd.mm.YYYY string.
-
#standardizes_number(number) ⇒ Object
As we are building a dd.mm.yyyy string, we want to standardize the size of the fields.
- #unit ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(series_name, series_code, series_periodicity, series_unit, series_day, series_month, series_year, series_value, seasonally_adjusted) ⇒ Data_bcb
Initialization is expected to express the state of a single row of data inside the BCB’s Database.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eba/data.rb', line 15 def initialize(series_name, series_code, series_periodicity, series_unit, series_day, series_month, series_year, series_value, seasonally_adjusted) @name = series_name @pk = series_code @periodicity = series_periodicity.to_s @unit = series_unit @date = standardizes_date(series_day, series_month, series_year) @value = series_value.to_f @seasonally_adjusted = seasonally_adjusted end |
Class Method Details
Instance Method Details
#compare_to(data_bcb) ⇒ Object
Simple comparission between two DataBCB objects.
157 158 159 160 161 162 |
# File 'lib/eba/data.rb', line 157 def compare_to(data_bcb) return (@name == data_bcb.name and @pk == data_bcb.pk \ and @periodicity == data_bcb.periodicity \ and @unit == data_bcb.unit and @date == data_bcb.date \ and @value = data_bcb.value and @seasonally_adjusted == data_bcb.seasonally_adjusted) end |
#date ⇒ Object
103 104 105 |
# File 'lib/eba/data.rb', line 103 def date return @date end |
#is_valid? ⇒ Boolean
37 38 39 40 41 42 43 44 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 75 76 77 78 79 80 |
# File 'lib/eba/data.rb', line 37 def is_valid? if @name == nil or @name == '' then puts "Found invalid name! Value is '#{@name}'" return false end if @periodicity == nil or @periodicity == '' or @periodicity.length > 1 then puts "Found invalid periodicity! Value is '#{@periodicity}'" return false end if @unit == nil or @unit == '' then puts "Found invalid unit! Value is '#{@unit}'" return false end if @date == nil or @date == '' then puts "Found invalid date! Value is '#{@date}'" return false else if !(DateTime.parse(@date).to_date != nil rescue false) then puts "Found invalid date! Value is '#{@date}'" return false end end if @value == nil then puts "Found invalid value! Value is '#{@value}'" return false else if !(@value.to_f != nil rescue false) then puts "Found invalid value! Value is '#{@value}'" return false end end if @pk == nil or @pk <= 0 then puts "Found invalid pk! Value is '#{@pk}'" return false end return true end |
#key ⇒ Object
Return an “identification key” with data which should be unique to a series (grouped).
29 30 31 |
# File 'lib/eba/data.rb', line 29 def key() return @name + @periodicity.to_s + @unit end |
#name ⇒ Object
91 92 93 |
# File 'lib/eba/data.rb', line 91 def name return @name end |
#periodicity ⇒ Object
95 96 97 |
# File 'lib/eba/data.rb', line 95 def periodicity return @periodicity end |
#pk ⇒ Object
Note that there are no set methods in this class, I built it in such a way that you are only intended to access data in the rawest form as possible as it comes from the BCB Webservice.
87 88 89 |
# File 'lib/eba/data.rb', line 87 def pk return @pk end |
#print ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/eba/data.rb', line 148 def print() return "Name: #{@name}\n" + "BCB Code: #{@pk}\n" + "Periodicity: #{@periodicity}\n" + "Unit: #{@unit} Seasonally Adjusted? #{@seasonally_adjusted ? 'YES' : 'NO'}\n" + "Date: #{@date} Value: #{@value}\n" end |
#seasonally_adjusted ⇒ Object
111 112 113 |
# File 'lib/eba/data.rb', line 111 def seasonally_adjusted return @seasonally_adjusted end |
#standardizes_date(day, month, year) ⇒ Object
The Webservice will always supply the date in three separate fields, this methods aim to convert it to a standard dd.mm.YYYY string.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/eba/data.rb', line 117 def standardizes_date(day, month, year) if day == '' or day == nil then day = "01" end if month == '' or month == nil then month = "01" end if year == '' or year == nil then year = "1900" end if month.to_i > 1900 then year = month month = "01" end return "#{standardizes_number(day.to_i)}.#{standardizes_number(month.to_i)}.#{year}" end |
#standardizes_number(number) ⇒ Object
As we are building a dd.mm.yyyy string, we want to standardize the size of the fields.
140 141 142 143 144 145 146 |
# File 'lib/eba/data.rb', line 140 def standardizes_number(number) if (number < 10) return "0#{number}" else return "#{number}" end end |
#unit ⇒ Object
99 100 101 |
# File 'lib/eba/data.rb', line 99 def unit return @unit end |
#value ⇒ Object
107 108 109 |
# File 'lib/eba/data.rb', line 107 def value return @value end |