Class: Sample

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sample.rb

Instance Method Summary collapse

Instance Method Details

#api_attributesObject



16
17
18
# File 'app/models/sample.rb', line 16

def api_attributes
  "TODO"
end

#fileObject



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

#labelObject



21
22
23
# File 'app/models/sample.rb', line 21

def label
  "#{country.full_name} #{year}"
end

#microdata_filesizeObject



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_householdObject



47
48
49
# File 'app/models/sample.rb', line 47

def offset_for_household
  @@household_offset ||= offset_for_rectype('H')
end

#offset_for_personObject



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_nameObject



32
33
34
# File 'app/models/sample.rb', line 32

def short_country_name
  country.short_name.upcase
end

#short_yearObject



37
38
39
# File 'app/models/sample.rb', line 37

def short_year
  year.to_s[-2,2]
end