Class: Hyrax::ControlledVocabulary::Importer::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/controlled_vocabulary/importer/language.rb

Constant Summary collapse

URL =
'http://www.lexvo.org/resources/lexvo_2013-02-09.rdf.gz'.freeze

Instance Method Summary collapse

Constructor Details

#initializeLanguage

Returns a new instance of Language.



9
10
11
12
13
14
15
16
# File 'lib/hyrax/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

Instance Method Details

#downloadObject



44
45
46
47
48
# File 'lib/hyrax/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_dirObject



54
55
56
57
58
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 54

def download_dir
  @download_dir ||= Rails.root.join('tmp')
  FileUtils.mkdir_p @download_dir
  @download_dir
end

#download_pathObject



50
51
52
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 50

def download_path
  File.join(download_dir, File.basename(URL))
end

#extractObject



37
38
39
40
41
42
# File 'lib/hyrax/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

#importObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hyrax/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::URI('http://www.w3.org/2008/05/skos#prefLabel')
  )
  logger.info "Import complete"
end

#rdf_pathObject



33
34
35
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 33

def rdf_path
  @rdf_path ||= download_path.sub(/\.gz$/, '')
end