Class: Course
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Course
show all
- Extended by:
- FriendlyId
- Defined in:
- app/models/course.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.calculate(current_certs, desired_certs) ⇒ Object
52
53
54
55
56
57
58
|
# File 'app/models/course.rb', line 52
def self.calculate(current_certs, desired_certs)
current = [current_certs[:tec_cert], current_certs[:rec_cert], current_certs[:ean], current_certs[:deep], current_certs[:efr]].flatten.compact.uniq.delete_if{|e| e == '0'}
current = (Course.find(current).map(&:course_ids) + current.map(&:to_i)).flatten.uniq
desired = [desired_certs[:rec_cert], desired_certs[:spec].try("keys"), desired_certs[:pro_cert], desired_certs[:pro_spec].try("keys"), desired_certs[:tec_cert], desired_certs[:pro_tec_cert]].flatten.compact.uniq.delete_if{|e| e == '0'}
desired = (Course.find(desired).map(&:course_ids) + desired.map(&:to_i)).flatten.uniq - current
Course.find(desired)
end
|
.discount?(course_prices) ⇒ Boolean
27
28
29
|
# File 'app/models/course.rb', line 27
def self.discount?(course_prices)
(course_prices - TecCourse.all - ProTecCourse.all).sum(&:course_price) > 999
end
|
.pro?(desired_certs) ⇒ Boolean
31
32
33
34
|
# File 'app/models/course.rb', line 31
def self.pro?(desired_certs)
desired_certs = Course.find(desired_certs.values.map{|e| e.is_a?(Hash) ? e.keys : e}.flatten - ['0'])
!(desired_certs & (ProCourse.all + ProSpecCourse.all + ProTecCourse.all)).empty?
end
|
.rec?(desired_certs) ⇒ Boolean
36
37
38
39
|
# File 'app/models/course.rb', line 36
def self.rec?(desired_certs)
desired_certs = Course.find(desired_certs.values.map{|e| e.is_a?(Hash) ? e.keys : e}.flatten - ['0'])
!(desired_certs & (RecCourse.all + RecSpecCourse.all)).empty?
end
|
.tec?(desired_certs) ⇒ Boolean
41
42
43
44
|
# File 'app/models/course.rb', line 41
def self.tec?(desired_certs)
desired_certs = Course.find(desired_certs.values.map{|e| e.is_a?(Hash) ? e.keys : e}.flatten - ['0'])
!(desired_certs & (TecCourse.all)).empty?
end
|
Instance Method Details
#course_price(discount = false) ⇒ Object
46
47
48
49
50
|
# File 'app/models/course.rb', line 46
def course_price(discount = false)
price = self.read_attribute(:course_price)
return nil unless price
(discount && ([self] & [ProTecCourse.all + TecCourse.all].flatten).empty?) ? price * 0.9 : price
end
|
#map_for_select ⇒ Object
23
24
25
|
# File 'app/models/course.rb', line 23
def map_for_select
[name, id.to_s]
end
|
#total(discount = false) ⇒ Object
19
20
21
|
# File 'app/models/course.rb', line 19
def total(discount = false)
course_price(discount) + materials_price + application_price
end
|