class Sufia::ControlledVocabulary::Importer::Language

Constants

URL

Public Class Methods

new() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 9
def initialize
  stdout_logger = Logger.new(STDOUT)
  stdout_logger.level = Logger::INFO
  stdout_logger.formatter = proc do |_severity, _datetime, _progname, msg|
    "#{msg}\n"
  end
  Rails.logger.extend(ActiveSupport::Logger.broadcast(stdout_logger))
end

Public Instance Methods

download() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 44
def download
  return if File.exist?(rdf_path) || File.exist?(download_path)
  logger.info "Downloading #{URL}"
  Downloader.fetch(URL, download_path)
end
download_dir() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 54
def download_dir
  @download_dir ||= File.join(Rails.root, 'tmp')
  FileUtils.mkdir_p @download_dir
  @download_dir
end
download_path() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 50
def download_path
  File.join(download_dir, File.basename(URL))
end
extract() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 37
def extract
  return if File.exist?(rdf_path)
  logger.info "Extracting #{download_path}"
  system("gunzip #{download_path}")
  raise "Unable to extract #{download_path}" unless $CHILD_STATUS.success?
end
import() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 18
def import
  download
  extract
  logger.info "Importing #{rdf_path}"
  Qa::Services::RDFAuthorityParser.import_rdf(
    'languages',
    [rdf_path],
    format: 'rdfxml',
    predicate: RDF::Vocab::SKOS.prefLabel
  )
  logger.info "Import complete"
end
rdf_path() click to toggle source
# File lib/sufia/controlled_vocabulary/importer/language.rb, line 33
def rdf_path
  @rdf_path ||= download_path.sub(/\.gz$/, '')
end