Class: Sample
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sample
- Defined in:
- app/models/sample.rb
Instance Method Summary collapse
- #api_attributes ⇒ Object
- #file ⇒ Object
- #label ⇒ Object
- #microdata_filesize ⇒ Object
- #offset_for_household ⇒ Object
- #offset_for_person ⇒ Object
- #offset_for_rectype(rectype) ⇒ Object
- #short_country_name ⇒ Object
- #short_year ⇒ Object
Instance Method Details
#api_attributes ⇒ Object
16 17 18 |
# File 'app/models/sample.rb', line 16 def api_attributes "TODO" end |
#file ⇒ Object
26 27 28 29 |
# File 'app/models/sample.rb', line 26 def file #File.join(TerrapopConfiguration['application']['environments'][Rails.env]['source_data']['microdata'], data_file_name) File.join(TerrapopConfiguration.settings['source_data']['microdata'], data_file_name) end |
#label ⇒ Object
21 22 23 |
# File 'app/models/sample.rb', line 21 def label "#{country.full_name} #{year}" end |
#microdata_filesize ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/sample.rb', line 57 def microdata_filesize if filesize.nil? or filesize == 0 _file = file if File.exist? _file filesize = File.size _file save elsif File.exist?("#{_file}.gz") filename = "#{_file}.gz" f = File.open(filename, 'rb') unless f.nil? f.seek(File.size(filename) - 4) a = f.readbyte b = f.readbyte c = f.readbyte d = f.readbyte filesize = (a << 24) | (b << 16) + (c << 8) + d; save end end end filesize end |
#offset_for_household ⇒ Object
47 48 49 |
# File 'app/models/sample.rb', line 47 def offset_for_household @@household_offset ||= offset_for_rectype('H') end |
#offset_for_person ⇒ Object
42 43 44 |
# File 'app/models/sample.rb', line 42 def offset_for_person @@person_offset ||= offset_for_rectype('P') end |
#offset_for_rectype(rectype) ⇒ Object
52 53 54 |
# File 'app/models/sample.rb', line 52 def offset_for_rectype(rectype) Variable.where(record_type: rectype, is_svar: false).maximum("column_start + column_width") end |
#short_country_name ⇒ Object
32 33 34 |
# File 'app/models/sample.rb', line 32 def short_country_name country.short_name.upcase end |
#short_year ⇒ Object
37 38 39 |
# File 'app/models/sample.rb', line 37 def short_year year.to_s[-2,2] end |