Class: Procedo::Engine::Intervention::Target

Inherits:
ProductParameter show all
Defined in:
lib/procedo/engine/intervention/target.rb

Instance Attribute Summary collapse

Attributes inherited from ProductParameter

#assembly, #component, #product, #read_at, #readings, #working_zone

Attributes inherited from Parameter

#group, #id, #intervention, #name, #reference, #type

Instance Method Summary collapse

Methods inherited from ProductParameter

#add_reading, #assembly?, #assembly_id, #assembly_id=, #component?, #component_id, #component_id=, #compute_attribute, #compute_reading, #impact_dependencies!, #impact_on_attributes, #impact_on_components, #impact_on_parameters, #impact_on_readings, #impact_with, #product?, #product_id, #product_id=, #read_at?, #reading, #usable_attribute?, #usable_handler?, #usable_reading?, #working_zone?

Methods inherited from Parameter

#dependents, #impact_dependencies!, #impact_with, #param_name, #root?

Methods included from Reassignable

#assign, #assign!, #reassign, #reassign!

Constructor Details

#initialize(intervention, id, attributes = {}) ⇒ Target

Returns a new instance of Target.


10
11
12
13
14
15
# File 'lib/procedo/engine/intervention/target.rb', line 10

def initialize(intervention, id, attributes = {})
  super(intervention, id, attributes)
  attributes = Maybe(attributes)
  @new_group = Product.find_by(id: attributes[:new_group].to_i.or_else(0))
  @new_container = Product.find_by(id: attributes[:new_container].to_i.or_else(0))
end

Instance Attribute Details

#identification_numberObject

Returns the value of attribute identification_number


8
9
10
# File 'lib/procedo/engine/intervention/target.rb', line 8

def identification_number
  @identification_number
end

#new_containerObject

Returns the value of attribute new_container


7
8
9
# File 'lib/procedo/engine/intervention/target.rb', line 7

def new_container
  @new_container
end

#new_groupObject

Returns the value of attribute new_group


7
8
9
# File 'lib/procedo/engine/intervention/target.rb', line 7

def new_group
  @new_group
end

#new_variantObject

Returns the value of attribute new_variant


8
9
10
# File 'lib/procedo/engine/intervention/target.rb', line 8

def new_variant
  @new_variant
end

Instance Method Details

#envObject


69
70
71
# File 'lib/procedo/engine/intervention/target.rb', line 69

def env
  super.merge(new_group: new_group)
end

#new_container_idObject


30
31
32
# File 'lib/procedo/engine/intervention/target.rb', line 30

def new_container_id
  @new_container ? @new_container.id : nil
end

#new_container_id=(id) ⇒ Object


38
39
40
41
# File 'lib/procedo/engine/intervention/target.rb', line 38

def new_container_id=(id)
  @new_container = Product.find_by(id: id)
  impact_dependencies!(:new_container)
end

#new_group_idObject


17
18
19
# File 'lib/procedo/engine/intervention/target.rb', line 17

def new_group_id
  @new_group ? @new_group.id : nil
end

#new_group_id=(id) ⇒ Object


25
26
27
28
# File 'lib/procedo/engine/intervention/target.rb', line 25

def new_group_id=(id)
  @new_group = Product.find_by(id: id)
  impact_dependencies!(:new_group)
end

#new_variant_idObject


43
44
45
# File 'lib/procedo/engine/intervention/target.rb', line 43

def new_variant_id
  new_variant ? new_variant.id : nil
end

#new_variant_id=(id) ⇒ Object


47
48
49
# File 'lib/procedo/engine/intervention/target.rb', line 47

def new_variant_id=(id)
  self.new_variant = ProductNatureVariant.find_by(id: id)
end

#to_attributesObject


60
61
62
63
64
65
66
67
# File 'lib/procedo/engine/intervention/target.rb', line 60

def to_attributes
  hash = super
  hash[:new_group_id] = new_group_id if @new_group
  hash[:new_container_id] = new_container_id if @new_container
  hash[:new_variant_id] = new_variant_id unless new_variant_id.nil?
  hash[:identification_number] = identification_number if @identification_number
  hash
end

#to_hashObject


51
52
53
54
55
56
57
58
# File 'lib/procedo/engine/intervention/target.rb', line 51

def to_hash
  hash = super
  hash[:new_group_id] = new_group_id if @new_group
  hash[:new_container_id] = new_container_id if @new_container
  hash[:new_variant_id] = new_variant_id unless new_variant_id.nil?
  hash[:identification_number] = identification_number if @identification_number
  hash
end