Class: Hyrax::ControlledVocabulary::Importer::Language
- Inherits:
-
Object
- Object
- Hyrax::ControlledVocabulary::Importer::Language
- 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
- #download ⇒ Object
- #download_dir ⇒ Object
- #download_path ⇒ Object
- #extract ⇒ Object
- #import ⇒ Object
-
#initialize ⇒ Language
constructor
A new instance of Language.
- #rdf_path ⇒ Object
Constructor Details
#initialize ⇒ Language
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
#download ⇒ Object
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_dir ⇒ Object
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_path ⇒ Object
51 52 53 |
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 51 def download_path File.join(download_dir, File.basename(URL)) end |
#extract ⇒ Object
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 |
#import ⇒ Object
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_path ⇒ Object
34 35 36 |
# File 'lib/hyrax/controlled_vocabulary/importer/language.rb', line 34 def rdf_path @rdf_path ||= download_path.sub(/\.gz$/, '') end |