Class AnnotationCategory
In: app/models/annotation_category.rb
Parent: ActiveRecord::Base

Methods

Public Class methods

Takes two arrays, one with annotation catogies names and one with associated annotation texts It is used with the Yaml format Format : annotation_category:

  • annotation_text
  • annotation_text

[Source]

    # File app/models/annotation_category.rb, line 50
50:   def self.add_by_array(annotation_category_name, annotation_texts_content, assignment)
51:     result = {}
52:     result[:annotation_upload_invalid_lines] = []
53:     annotation_category = assignment.annotation_categories.find_by_annotation_category_name(annotation_category_name)
54:     if annotation_category.nil?
55:       # Create a new annotation category

56:       annotation_category = AnnotationCategory.new
57:       annotation_category.annotation_category_name = annotation_category_name
58:       annotation_category.assignment = assignment
59:       annotation_category.save!
60:     end
61:     annotation_texts_content.at(0).each do |text|
62:       annotation_text = AnnotationText.new
63:       annotation_text.content = text.to_s
64:       annotation_text.annotation_category = annotation_category
65:       if !annotation_text.save
66:         # This line checks for the case where we are not given a category name

67:         annotation_category_name = "" if annotation_category_name.nil?
68:         # If for some reason we are not able to update the category

69:         # send the respective error

70:         result[:annotation_upload_invalid_lines].push(annotation_category_name)
71:       end
72:     end
73:     return result
74:   end

Takes an array of comma separated values, and tries to assemble an Annotation Category, and associated Annotation Texts Format: annotation_category,annotation_text,annotation_text,…

[Source]

    # File app/models/annotation_category.rb, line 12
12:   def self.add_by_row(row, assignment)
13:     result = {}
14:     result[:annotation_upload_invalid_lines] = []
15:     # The first column is the annotation category name...

16:     annotation_category_name = row.shift
17:     annotation_category = assignment.annotation_categories.find_by_annotation_category_name(annotation_category_name)
18:     if annotation_category.nil?
19:       # Create a new annotation category

20:       annotation_category = AnnotationCategory.new
21:       annotation_category.annotation_category_name = annotation_category_name
22:       annotation_category.assignment = assignment
23:       annotation_category.save
24:     end
25:     
26:     row.each do |annotation_text_content|
27:       annotation_text = AnnotationText.new
28:       annotation_text.content = annotation_text_content
29:       annotation_text.annotation_category = annotation_category
30:       if !annotation_text.save
31:         # This line checks for the case where we are not given a category name

32:         # i.e ,123

33:         annotation_category_name = "" if annotation_category_name.nil?
34:         # If for some reason we are not able to update the category

35:         # send the respective error

36:         result[:annotation_upload_invalid_lines].push(annotation_category_name)
37:       end
38:     end
39:     return result
40:   end

[Validate]