Skip to content
Snippets Groups Projects
Commit db167209 authored by Lucas Gabriel Lima's avatar Lucas Gabriel Lima
Browse files

Merge branch 'feature-tags' of gitlab.c3sl.ufpr.br:portalmec/portalmec into feature-tags

parents 6e474afd d1a72200
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,18 @@ class TagsImporter
attr_accessor :items
def import
tags = {}
@items.each do |learning_object|
learning_object.tag_list = parse_tags learning_object.get_metadata_values_of 'dc.subject.category'
learning_object.save
categories = parse_tags learning_object.get_metadata_values_of 'dc.subject.category'
keywords = learning_object.get_metadata_values_of 'dc.subject.keyword'
(categories + keywords).each do |tag_name|
unless tag_exists?(tag_name, tags)
tags[tag_name] = Tag.new(name: tag_name)
end
end
end
Tag.import tags.values
end
private
......@@ -15,4 +23,9 @@ class TagsImporter
values.compact.each { |value| tags << value.split('::') }
tags.flatten.uniq.map(&:strip)
end
def tag_exists? (tag_name, tags)
!Tag.find_by_name(tag_name).nil? || !tags[tag_name].nil?
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment