Class: WageStats
- Inherits:
-
Object
- Object
- WageStats
- Defined in:
- lib/salary_croatia.rb
Constant Summary collapse
- @@average_salary_hash =
{}
- @@dates_hash =
{}
- @@merged_hash =
{}
Instance Attribute Summary collapse
-
#download_url ⇒ Object
Returns the value of attribute download_url.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
Class Method Summary collapse
-
.convert_dates_array(dates_array) ⇒ Object
——————————————————————————.
-
.get_latest_average_salary ⇒ Object
—————————————————————————— Basically last month value of average national net salary.
-
.get_salary_for_date(date) ⇒ Object
——————————————————————————.
- .get_salary_history ⇒ Object
-
.get_year_of_salaries(year) ⇒ Object
——————————————————————————.
-
.merge_arrays ⇒ Object
——————————————————————————.
-
.update_stats(filename = FILE_NAME, download_url = WAGE_STATISTICS_URL) ⇒ Object
class method, that is using default values for download and file_name.
Instance Attribute Details
#download_url ⇒ Object
Returns the value of attribute download_url.
10 11 12 |
# File 'lib/salary_croatia.rb', line 10 def download_url @download_url end |
#file_name ⇒ Object
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/salary_croatia.rb', line 10 def file_name @file_name end |
Class Method Details
.convert_dates_array(dates_array) ⇒ Object
111 112 113 114 |
# File 'lib/salary_croatia.rb', line 111 def self.convert_dates_array(dates_array) cd = ConvertDate.new cd.get_dates(dates_array) end |
.get_latest_average_salary ⇒ Object
Basically last month value of average national net salary
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/salary_croatia.rb', line 38 def self.get_latest_average_salary if File.exists?(FILE_NAME) self.update_stats end if @@merged_hash.empty? self.update_stats self.merge_arrays end @@average_salary_hash.values.last end |
.get_salary_for_date(date) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/salary_croatia.rb', line 52 def self.get_salary_for_date(date) if @@merged_hash.empty? self.update_stats self.merge_arrays end converted_date = ConvertDate.new.transform_date(date) return @@merged_hash[converted_date.to_s] end |
.get_salary_history ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/salary_croatia.rb', line 81 def self.get_salary_history if @@merged_hash.empty? self.update_stats self.merge_arrays end return @@merged_hash end |
.get_year_of_salaries(year) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/salary_croatia.rb', line 63 def self.get_year_of_salaries(year) if @@merged_hash.empty? self.update_stats self.merge_arrays end year_salaries = [] @@merged_hash.values.each_with_index do |value, index| if @@merged_hash.keys[index].include?(year) and year.length > 3 year_salaries << value end end return year_salaries end |
.merge_arrays ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/salary_croatia.rb', line 91 def self.merge_arrays dates_array = self.convert_dates_array(@@dates_hash.values.drop(2)) salaries_array = @@average_salary_hash.values.drop(2) # Removing 2 empty cells from the start of an array while dates_array.size > salaries_array.size dates_array.pop end if dates_array.size == salaries_array.size @@merged_hash = DataTypeHelper.merge_arrays_into_hash(dates_array, salaries_array) else puts "Dates size: " + dates_array.size.to_s puts dates_array puts "Salary size: " + salaries_array.size.to_s puts salaries_array raise Exception.new "Arrays have different size, thus incompatible" end end |
.update_stats(filename = FILE_NAME, download_url = WAGE_STATISTICS_URL) ⇒ Object
class method, that is using default values for download and file_name
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/salary_croatia.rb', line 17 def self.update_stats(filename=FILE_NAME, download_url=WAGE_STATISTICS_URL) if !File.file?(filename) or download_url != WAGE_STATISTICS_URL File.open(filename, "wb") do |saved_file| open(download_url, "rb") do |read_file| saved_file.write(read_file.read) end end #puts "Updated stats!" end if (@@average_salary_hash.empty?) file_data = Creek::Book.new filename file_data.sheets[0].rows.each_with_index do |row, index| @@average_salary_hash = row if index == 75 @@dates_hash = row if index == 6 end end end |