class Ruian::EnumUpdater

Constants

URL

Public Instance Methods

download() click to toggle source
# File lib/ruian/enum_updater.rb, line 16
def download
  File.open(filepath, "wb") do |file|
    open(URL) do |url|
      file.write(url.read)
    end
  end
end
filepath() click to toggle source
# File lib/ruian/enum_updater.rb, line 51
def filepath
  Ruian.root.join('fixtures', 'enum.zip')
end
fixtures_directory() click to toggle source
# File lib/ruian/enum_updater.rb, line 47
def fixtures_directory
  Ruian.root.join('fixtures')
end
needed() click to toggle source
# File lib/ruian/enum_updater.rb, line 55
def needed
  ['vazby-cr.csv', 'vazby-okresy-cr.csv']
end
remove_old() click to toggle source
# File lib/ruian/enum_updater.rb, line 36
def remove_old
  first = fixtures_directory.join(needed.first)
  last = fixtures_directory.join(needed.last)
  FileUtils.rm(first) if File.exists?(first)
  FileUtils.rm(last) if File.exists?(last)
end
remove_temp() click to toggle source
# File lib/ruian/enum_updater.rb, line 43
def remove_temp
  FileUtils.rm(filepath)
end
unpack() click to toggle source
# File lib/ruian/enum_updater.rb, line 24
def unpack
  Zip::File.open(filepath) do |zip_file|
    zip_file.each do |entry|
      name = File.basename(entry.name)
      if needed.include?(name)
        fullpath = fixtures_directory.join(name)
        entry.extract(fullpath)
      end
    end
  end
end
update!() click to toggle source
# File lib/ruian/enum_updater.rb, line 9
def update!
  download
  remove_old
  unpack
  remove_temp
end