Class: Course
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Course
show all
- Defined in:
- app/models/course.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.calculate(current_certs, desired_certs) ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/models/course.rb', line 45
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
20
21
22
|
# File 'app/models/course.rb', line 20
def self.discount?(course_prices)
(course_prices - TecCourse.all - ProTecCourse.all).sum(&:course_price) > 999
end
|
.pro?(desired_certs) ⇒ Boolean
24
25
26
27
|
# File 'app/models/course.rb', line 24
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
29
30
31
32
|
# File 'app/models/course.rb', line 29
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
34
35
36
37
|
# File 'app/models/course.rb', line 34
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
39
40
41
42
43
|
# File 'app/models/course.rb', line 39
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
16
17
18
|
# File 'app/models/course.rb', line 16
def map_for_select
[name, id.to_s]
end
|
#total(discount = false) ⇒ Object
12
13
14
|
# File 'app/models/course.rb', line 12
def total(discount = false)
course_price(discount) + materials_price + application_price
end
|