Class: Ecom::Core::TaskTemplate

Inherits:
ApplicationRecord show all
Defined in:
app/models/ecom/core/task_template.rb

Instance Method Summary collapse

Instance Method Details

#crew_typesObject



35
36
37
# File 'app/models/ecom/core/task_template.rb', line 35

def crew_types
  resource_types.where(type: 'Ecom::Core::CrewType')
end

#equipment_typesObject



43
44
45
# File 'app/models/ecom/core/task_template.rb', line 43

def equipment_types
  resource_types.where(type: 'Ecom::Core::EquipmentType')
end

#full_nameObject



28
29
30
31
32
33
# File 'app/models/ecom/core/task_template.rb', line 28

def full_name
  parent_name = parent&.name
  return name unless parent_name

  "#{name} - #{parent_name}"
end

#material_typesObject



39
40
41
# File 'app/models/ecom/core/task_template.rb', line 39

def material_types
  resource_types.where(type: 'Ecom::Core::MaterialType')
end

#percentage_contribution_sum_validatorObject



47
48
49
50
51
52
# File 'app/models/ecom/core/task_template.rb', line 47

def percentage_contribution_sum_validator
  return if percentage_contribution.nil?

  sum = siblings.sum(:percentage_contribution)
  errors.add(:task, 'Sum of percentage contributions has to be 100') if sum > 100
end