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'

Instance Method Summary collapse

Constructor Details

#initializeLanguage

Returns a new instance of Language.



10
11
12
13
14
15
16
17
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 10

def initialize
  stdout_logger = Logger.new(STDOUT)
  stdout_logger.level = Logger::INFO
  stdout_logger.formatter = proc do |_severity, _datetime, _progname, msg|
    "#{msg}\n"
  end
  Hyrax.logger.extend(ActiveSupport::Logger.broadcast(stdout_logger))
end

Instance Method Details

#downloadObject



45
46
47
48
49
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 45

def download
  return if File.exist?(rdf_path) || File.exist?(download_path)
  logger.info "Downloading #{URL}"
  Downloader.fetch(URL, download_path)
end

#download_dirObject



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

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

#download_pathObject



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

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

#extractObject



38
39
40
41
42
43
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 38

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



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 19

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



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

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