Class: Exercise
Instance Method Summary
collapse
#navigable_name, #next_for, #restart
#leave, #navigable_name, #navigable_parent, #navigation_end?
#find_assignment_and_submit!, #submit!
#submit_question!
#assigned_to?, #assignment_for, #current_content_for, #default_content_for, #extra_for, #files_for, #find_or_init_assignment_for, #has_messages_for?, #interpolate_for, #last_submission_date_for, #messages_for, #replace_content_reference, #solved_by?, #status_for, #submissions_count_for
#friendly_name, #to_param
#description_teaser
aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!
Instance Method Details
#console? ⇒ Boolean
22
23
24
|
# File 'app/models/exercise.rb', line 22
def console?
queriable?
end
|
#description_context ⇒ Object
117
118
119
|
# File 'app/models/exercise.rb', line 117
def description_context
Mumukit::ContentType::Markdown.to_html splitted_description.first
end
|
#description_task ⇒ Object
125
126
127
|
# File 'app/models/exercise.rb', line 125
def description_task
Mumukit::ContentType::Markdown.to_html splitted_description.drop(1).join("\n")
end
|
#ensure_type!(type) ⇒ Object
96
97
98
99
100
101
102
|
# File 'app/models/exercise.rb', line 96
def ensure_type!(type)
if self.type != type
reclassify! type
else
self
end
end
|
63
64
65
|
# File 'app/models/exercise.rb', line 63
def friendly
defaulting_name { "#{navigable_parent.friendly} - #{name}" }
end
|
#guide_done_for?(user) ⇒ Boolean
38
39
40
|
# File 'app/models/exercise.rb', line 38
def guide_done_for?(user)
guide.done_for?(user)
end
|
#import_from_json!(number, json) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/exercise.rb', line 71
def import_from_json!(number, json)
self.language = Language.for_name(json['language']) || guide.language
self.locale = guide.locale
reset!
attrs = json.except('type', 'id', 'solution', 'language', 'teacher_info', 'choices')
attrs['choices'] = json['choices'].map { |choice| choice['value'] } if json['choices'].present?
attrs['bibliotheca_id'] = json['id']
attrs['number'] = number
attrs = attrs.except('expectations') if json['type'] != 'problem' || json['new_expectations']
assign_attributes(attrs)
save!
end
|
#messages_path_for(user) ⇒ Object
109
110
111
|
# File 'app/models/exercise.rb', line 109
def messages_path_for(user)
"api/guides/#{guide.slug}/#{bibliotheca_id}/student/#{URI.escape user.uid}/messages?language=#{language}"
end
|
#messages_url_for(user) ⇒ Object
113
114
115
|
# File 'app/models/exercise.rb', line 113
def messages_url_for(user)
Mumukit::Platform.classroom_api.organic_url_for(Organization.current, messages_path_for(user))
end
|
#new_solution ⇒ Object
67
68
69
|
# File 'app/models/exercise.rb', line 67
def new_solution
Solution.new(content: default_content)
end
|
#pending_siblings_for(user) ⇒ Object
30
31
32
|
# File 'app/models/exercise.rb', line 30
def pending_siblings_for(user)
guide.pending_exercises(user)
end
|
42
43
44
|
# File 'app/models/exercise.rb', line 42
def previous
sibling_at number.pred
end
|
#reclassify!(type) ⇒ Object
104
105
106
107
|
# File 'app/models/exercise.rb', line 104
def reclassify!(type)
update!(type: Exercise.class_for(type).name)
Exercise.find(id)
end
|
87
88
89
90
91
92
93
94
|
# File 'app/models/exercise.rb', line 87
def reset!
self.name = nil
self.description = nil
self.corollary = nil
self.hint = nil
self. = nil
self.tag_list = []
end
|
51
52
53
|
# File 'app/models/exercise.rb', line 51
def search_tags
[language&.name, *tag_list].compact
end
|
#sibling_at(index) ⇒ Object
46
47
48
49
|
# File 'app/models/exercise.rb', line 46
def sibling_at(index)
index = number + index unless index.positive?
guide.exercises.find_by(number: index)
end
|
55
56
57
|
# File 'app/models/exercise.rb', line 55
def slug
"#{guide.slug}/#{bibliotheca_id}"
end
|
#slug_parts ⇒ Object
59
60
61
|
# File 'app/models/exercise.rb', line 59
def slug_parts
guide.slug_parts.merge(bibliotheca_id: bibliotheca_id)
end
|
#splitted_description ⇒ Object
121
122
123
|
# File 'app/models/exercise.rb', line 121
def splitted_description
description.split('> ')
end
|
#structural_parent ⇒ Object
34
35
36
|
# File 'app/models/exercise.rb', line 34
def structural_parent
guide
end
|
#used_in?(organization = Organization.current) ⇒ Boolean
26
27
28
|
# File 'app/models/exercise.rb', line 26
def used_in?(organization=Organization.current)
guide.usage_in_organization(organization).present?
end
|