Skip to content
Snippets Groups Projects
Commit 83f804d1 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 8d91943d 3f0f4457
No related branches found
No related tags found
No related merge requests found
......@@ -3,22 +3,33 @@ class TagsImporter
def import
tags = {}
taggings = []
@items.each do |learning_object|
categories = parse_tags learning_object.get_metadata_values_of 'dc.subject.category'
publisher = learning_object.publisher
categories = parse_categories 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)
tag = tags[tag_name]
else
tag= Tag.find_by_name tag_name
end
unless tagging_exists?(tag, publisher, learning_object)
taggings << Tagging.new(tag: tag, tagger: publisher, taggable: learning_object)
end
end
end
Tag.import tags.values
Tagging.import taggings
end
private
def parse_tags(values)
def parse_categories(values)
tags = []
values.compact.each { |value| tags << value.split('::') }
tags.flatten.uniq.map(&:strip)
......@@ -28,4 +39,8 @@ class TagsImporter
!Tag.find_by_name(tag_name).nil? || !tags[tag_name].nil?
end
def tagging_exists? (tag, tagger, taggable)
Tagging.where(tag: tag, tagger: tagger, taggable: taggable).exists?
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