Class: Procedo::Procedure::GroupParameter

Inherits:
Parameter
  • Object
show all
Defined in:
lib/procedo/procedure/group_parameter.rb

Overview

Parameter group is a a group of parameter like a directory in a FS.

Instance Attribute Summary

Attributes inherited from Parameter

#cardinality, #group, #name, #procedure

Instance Method Summary collapse

Methods inherited from Parameter

#depend_on?, #human_name, #inspect, #position, #reflection_name, type, #type

Constructor Details

#initialize(procedure, name, options = {}) ⇒ GroupParameter


7
8
9
10
# File 'lib/procedo/procedure/group_parameter.rb', line 7

def initialize(procedure, name, options = {})
  super(procedure, name, options)
  @parameters = {}.with_indifferent_access
end

Instance Method Details

#add_group_parameter(name, options = {}) ⇒ Object


91
92
93
94
95
# File 'lib/procedo/procedure/group_parameter.rb', line 91

def add_group_parameter(name, options = {})
  options[:group] = self
  parameter = Procedo::Procedure::GroupParameter.new(@procedure, name, options)
  @parameters[parameter.name] = parameter
end

#add_product_parameter(name, type, options = {}) ⇒ Object


85
86
87
88
89
# File 'lib/procedo/procedure/group_parameter.rb', line 85

def add_product_parameter(name, type, options = {})
  options[:group] = self
  parameter = Procedo::Procedure::ProductParameter.new(@procedure, name, type, options)
  @parameters[parameter.name] = parameter
end

#each_group_parameter(recursively = false, &_block) ⇒ Object

Browse group_parameters in their order


79
80
81
82
83
# File 'lib/procedo/procedure/group_parameter.rb', line 79

def each_group_parameter(recursively = false, &_block)
  each_parameter(recursively) do |parameter|
    yield(parameter) if parameter.is_a?(Procedo::Procedure::GroupParameter)
  end
end

#each_parameter(recursively = false, &block) ⇒ Object

Browse parameters in their order


67
68
69
# File 'lib/procedo/procedure/group_parameter.rb', line 67

def each_parameter(recursively = false, &block)
  recursively ? browse_all(&block) : @parameters.values.each(&block)
end

#each_product_parameter(recursively = false, &_block) ⇒ Object

Browse product_parameters in their order


72
73
74
75
76
# File 'lib/procedo/procedure/group_parameter.rb', line 72

def each_product_parameter(recursively = false, &_block)
  each_parameter(recursively) do |parameter|
    yield(parameter) if parameter.is_a?(Procedo::Procedure::ProductParameter)
  end
end

#fetch(name) ⇒ Object Also known as: []

Returns an parameter with its name


34
35
36
# File 'lib/procedo/procedure/group_parameter.rb', line 34

def fetch(name)
  @parameters[name]
end

#find(name, _type = nil) ⇒ Object

Returns parameter with its name. Returns nil if not found


40
41
42
43
44
45
# File 'lib/procedo/procedure/group_parameter.rb', line 40

def find(name, _type = nil)
  browse_all do |i|
    return i if i.name.to_s == name.to_s
  end
  nil
end

#find!(name) ⇒ Object

Returns parameter with its name. Raise exception if parameter not found


48
49
50
51
52
# File 'lib/procedo/procedure/group_parameter.rb', line 48

def find!(name)
  parameter = find(name)
  raise "Cannot find parameter: #{name.inspect}" unless parameter
  parameter
end

#group_parameters(recursively = false) ⇒ Object


18
19
20
# File 'lib/procedo/procedure/group_parameter.rb', line 18

def group_parameters(recursively = false)
  parameters(recursively).select { |i| i.is_a?(Procedo::Procedure::GroupParameter) }
end

#parameters(recursively = false) ⇒ Object

Returns all parameters of the group If recursively is true, it will retrieve all parameters of sub-groups too.


14
15
16
# File 'lib/procedo/procedure/group_parameter.rb', line 14

def parameters(recursively = false)
  recursively ? all_parameters : @parameters.values
end

#parameters_of_type(type, recursively = false) ⇒ Object


26
27
28
29
30
31
# File 'lib/procedo/procedure/group_parameter.rb', line 26

def parameters_of_type(type, recursively = false)
  parameters(recursively).select do |i|
    (i.is_a?(Procedo::Procedure::ProductParameter) && i.type == type) ||
      (i.is_a?(Procedo::Procedure::GroupParameter) && :group == type)
  end
end

#position_of(parameter) ⇒ Object

Returns position of a parameter in the group relatively to the current group parameter. First element has position 1.


57
58
59
60
61
62
63
64
# File 'lib/procedo/procedure/group_parameter.rb', line 57

def position_of(parameter)
  index = 1
  browse_all do |i|
    return index if i == parameter
    index += 1
  end
  nil
end

#product_parameters(recursively = false) ⇒ Object


22
23
24
# File 'lib/procedo/procedure/group_parameter.rb', line 22

def product_parameters(recursively = false)
  parameters(recursively).select { |i| i.is_a?(Procedo::Procedure::ProductParameter) }
end