Module: Procedo

Defined in:
lib/procedo.rb,
lib/procedo/xml.rb,
lib/procedo/engine.rb,
lib/procedo/errors.rb,
lib/procedo/formula.rb,
lib/procedo/procedure.rb,
lib/procedo/engine/set.rb,
lib/procedo/cardinality.rb,
lib/procedo/formula/nodes.rb,
lib/procedo/formula/parser.rb,
lib/procedo/procedure/field.rb,
lib/procedo/formula/language.rb,
lib/procedo/procedure/setter.rb,
lib/procedo/engine/functions.rb,
lib/procedo/procedure/handler.rb,
lib/procedo/procedure/reading.rb,
lib/procedo/engine/interpreter.rb,
lib/procedo/procedure/parameter.rb,
lib/procedo/procedure/attribute.rb,
lib/procedo/engine/intervention.rb,
lib/procedo/formula/syntax_error.rb,
lib/procedo/procedure/computation.rb,
lib/procedo/engine/intervention/doer.rb,
lib/procedo/engine/intervention/tool.rb,
lib/procedo/procedure/group_parameter.rb,
lib/procedo/engine/intervention/input.rb,
lib/procedo/engine/intervention/agent.rb,
lib/procedo/engine/intervention/target.rb,
lib/procedo/engine/intervention/output.rb,
lib/procedo/procedure/product_parameter.rb,
lib/procedo/engine/intervention/reading.rb,
lib/procedo/engine/intervention/parameter.rb,
lib/procedo/engine/intervention/quantified.rb,
lib/procedo/engine/intervention/working_period.rb,
lib/procedo/engine/intervention/group_parameter.rb,
lib/procedo/engine/intervention/product_parameter.rb

Overview

require 'procedo/engine/intervention/parameter'

Defined Under Namespace

Modules: CompiledProcedures, Engine, Errors, Formula Classes: Cardinality, Error, Procedure, XML

Constant Summary collapse

XML_NAMESPACE =
'http://www.ekylibre.org/XML/2013/procedures'.freeze
@@list =
HashWithIndifferentAccess.new

Class Method Summary collapse

Class Method Details

.each_parameterObject

Browse all parameters of all procedures


76
77
78
79
80
81
82
# File 'lib/procedo.rb', line 76

def each_parameter
  each_procedure do |procedure|
    procedure.parameters.each do |parameter|
      yield parameter
    end
  end
end

.each_procedureObject

Browse all available procedures


69
70
71
72
73
# File 'lib/procedo.rb', line 69

def each_procedure
  @@list.each do |_, procedure|
    yield procedure
  end
end

.each_product_parameterObject

Browse all parameters of all procedures


85
86
87
88
89
90
91
# File 'lib/procedo.rb', line 85

def each_product_parameter
  each_procedure do |procedure|
    procedure.product_parameters.each do |parameter|
      yield parameter
    end
  end
end

.each_variable(&block) ⇒ Object


93
94
95
96
# File 'lib/procedo.rb', line 93

def each_variable(&block)
  ActiveSupport::Deprecation.warn 'Procedo::each_variable is deprecated. Please use Procedo::each_parameter instead.'
  each_parameter(&block)
end

.find(name) ⇒ Object Also known as: []

Give access to named procedures


42
43
44
# File 'lib/procedo.rb', line 42

def find(name)
  @@list[name]
end

.loadObject

Load all files


99
100
101
102
103
104
105
106
107
# File 'lib/procedo.rb', line 99

def load
  # Inventory procedures
  Dir.glob(root.join('*.xml')).sort.each do |path|
    Procedo::XML.parse(path).each do |procedure|
      @@list[procedure.name] = procedure
    end
  end
  true
end

.procedure_namesObject

Returns the names of the procedures


32
33
34
# File 'lib/procedo.rb', line 32

def procedure_names
  @@list.keys
end

.proceduresObject


27
28
29
# File 'lib/procedo.rb', line 27

def procedures
  @@list.values
end

.procedures_of_activity_family(*families) ⇒ Object

Returns direct procedures of nature


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

def procedures_of_activity_family(*families)
  procedures.select do |p|
    p.of_activity_family?(*families)
  end
end

.procedures_of_category(*categories) ⇒ Object

Returns direct procedures of nature


55
56
57
58
59
# File 'lib/procedo.rb', line 55

def procedures_of_category(*categories)
  procedures.select do |p|
    p.of_category?(*categories)
  end
end

.procedures_of_main_category(*categories) ⇒ Object

Returns direct procedures of nature


62
63
64
65
66
# File 'lib/procedo.rb', line 62

def procedures_of_main_category(*categories)
  procedures.select do |p|
    categories.detect { |c| p.categories.first <= c }
  end
end

.rootObject

Returns the root of the procedures


110
111
112
# File 'lib/procedo.rb', line 110

def root
  Rails.root.join('config', 'procedures')
end

.selectionObject

Returns an array of couple human_name/name sorted by human name.


37
38
39
# File 'lib/procedo.rb', line 37

def selection
  procedures.map { |p| [p.human_name, p.name.to_s] }.sort { |a, b| I18n.transliterate(a.first) <=> I18n.transliterate(b.first) }
end