Class: Exercise
- Inherits:
-
ApplicationRecord
show all
- Includes:
- Assistable, FriendlyName, ParentNavigation, Questionable, SiblingsNavigation, Submittable, WithAssignments, WithDescription, WithDiscussions, WithLanguage, WithLocale, WithNumber, WithRandomizations
- Defined in:
- app/models/exercise.rb
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
Methods included from Assistable
#assist_with, #assistant
#randomizer, #seed, #seed_with!
#discuss!, #try_solve_discussions
#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
26
27
28
|
# File 'app/models/exercise.rb', line 26
def console?
queriable?
end
|
#custom? ⇒ Boolean
137
138
139
|
# File 'app/models/exercise.rb', line 137
def custom?
false
end
|
#description_context ⇒ Object
125
126
127
|
# File 'app/models/exercise.rb', line 125
def description_context
Mumukit::ContentType::Markdown.to_html splitted_description.first
end
|
#description_task ⇒ Object
133
134
135
|
# File 'app/models/exercise.rb', line 133
def description_task
Mumukit::ContentType::Markdown.to_html splitted_description.drop(1).join("\n")
end
|
#ensure_type!(type) ⇒ Object
104
105
106
107
108
109
110
|
# File 'app/models/exercise.rb', line 104
def ensure_type!(type)
if self.type != type
reclassify! type
else
self
end
end
|
#friendly ⇒ Object
67
68
69
|
# File 'app/models/exercise.rb', line 67
def friendly
defaulting_name { "#{navigable_parent.friendly} - #{name}" }
end
|
#guide_done_for?(user) ⇒ Boolean
42
43
44
|
# File 'app/models/exercise.rb', line 42
def guide_done_for?(user)
guide.done_for?(user)
end
|
#import_from_json!(number, json) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/models/exercise.rb', line 79
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
|
#inspection_keywords ⇒ Object
141
142
143
|
# File 'app/models/exercise.rb', line 141
def inspection_keywords
{}
end
|
#messages_path_for(user) ⇒ Object
117
118
119
|
# File 'app/models/exercise.rb', line 117
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
121
122
123
|
# File 'app/models/exercise.rb', line 121
def messages_url_for(user)
Mumukit::Platform.classroom_api.organic_url_for(Organization.current, messages_path_for(user))
end
|
#new_solution ⇒ Object
75
76
77
|
# File 'app/models/exercise.rb', line 75
def new_solution
Solution.new(content: default_content)
end
|
#pending_siblings_for(user) ⇒ Object
34
35
36
|
# File 'app/models/exercise.rb', line 34
def pending_siblings_for(user)
guide.pending_exercises(user)
end
|
#previous ⇒ Object
46
47
48
|
# File 'app/models/exercise.rb', line 46
def previous
sibling_at number.pred
end
|
#reclassify!(type) ⇒ Object
112
113
114
115
|
# File 'app/models/exercise.rb', line 112
def reclassify!(type)
update!(type: Exercise.class_for(type).name)
Exercise.find(id)
end
|
#reset! ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'app/models/exercise.rb', line 95
def reset!
self.name = nil
self.description = nil
self.corollary = nil
self.hint = nil
self. = nil
self.tag_list = []
end
|
55
56
57
|
# File 'app/models/exercise.rb', line 55
def search_tags
[language&.name, *tag_list].compact
end
|
#sibling_at(index) ⇒ Object
50
51
52
53
|
# File 'app/models/exercise.rb', line 50
def sibling_at(index)
index = number + index unless index.positive?
guide.exercises.find_by(number: index)
end
|
#slug ⇒ Object
59
60
61
|
# File 'app/models/exercise.rb', line 59
def slug
"#{guide.slug}/#{bibliotheca_id}"
end
|
#slug_parts ⇒ Object
63
64
65
|
# File 'app/models/exercise.rb', line 63
def slug_parts
guide.slug_parts.merge(bibliotheca_id: bibliotheca_id)
end
|
#splitted_description ⇒ Object
129
130
131
|
# File 'app/models/exercise.rb', line 129
def splitted_description
description.split('> ')
end
|
#structural_parent ⇒ Object
38
39
40
|
# File 'app/models/exercise.rb', line 38
def structural_parent
guide
end
|
#submission_for(user) ⇒ Object
71
72
73
|
# File 'app/models/exercise.rb', line 71
def submission_for(user)
assignment_for(user)&.submission
end
|
#used_in?(organization = Organization.current) ⇒ Boolean
30
31
32
|
# File 'app/models/exercise.rb', line 30
def used_in?(organization=Organization.current)
guide.usage_in_organization(organization).present?
end
|