| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/models/annotation_category.rb | 75 | 51 | 80.00%
|
84.31%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 class AnnotationCategory < ActiveRecord::Base |
2 validates_presence_of :annotation_category_name |
3 has_many :annotation_texts, :dependent => :destroy |
4 belongs_to :assignment |
5 validates_uniqueness_of :annotation_category_name, :scope => :assignment_id, :message => 'is already taken' |
6 validates_presence_of :assignment_id |
7 validates_associated :assignment, :message => 'not strongly associated with assignment' |
8 |
9 # Takes an array of comma separated values, and tries to assemble an |
10 # Annotation Category, and associated Annotation Texts |
11 # Format: annotation_category,annotation_text,annotation_text,... |
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 |
41 |
42 # Takes two arrays, one with annotation catogies names and one |
43 # with associated annotation texts |
44 # It is used with the Yaml format |
45 # Format : |
46 # annotation_category: |
47 # - annotation_text |
48 # - annotation_text |
49 # … |
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 |
75 end |
Generated on Tue Feb 07 00:07:35 -0500 2012 with rcov 0.9.10