Class: Scan::Model::ParseMetadataJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/scan/model/parse_metadata_job.rb

Constant Summary collapse

README_FILES =
[
  "readme",
  "readme.md",
  "readme.txt"
]

Instance Method Summary collapse

Instance Method Details

#perform(model_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/jobs/scan/model/parse_metadata_job.rb', line 11

def perform(model_id)
  model = Model.find(model_id)
  return if model.remote?
  # Loads metadata in order of priority; README, datapackage, path template,
  # Some things are high-priority if already set
  options = {
    creator: model.creator,
    collections: model.collections,
    preview_file: model.preview_file,
    notes: model.notes,
    tag_list: model.tag_list
  }.compact_blank
  # Load information from READMEs
  options = combine_options options, attributes_from_readme(model.model_files.find_by(filename_lower: README_FILES))
  # Load from datapackage
  options = combine_options options, attributes_from_datapackage(model)
  # Set path template attributes
  options = combine_options options, attributes_from_path_template(model.library, model.path)
  # Add additional tags
  tag_list = tags_from_directory_name(model.path) + tags_from_path_template(model.library, model.path)
  options[:tag_list] = (options[:tag_list] || []) + remove_stop_words(tag_list.uniq)
  # Set preview file
  options = combine_options options, identify_preview_file(model)
  # Store new metadata
  model.update!(options.compact_blank!)
end