Class: Caixanegra::Unit
- Inherits:
-
Object
- Object
- Caixanegra::Unit
- Defined in:
- lib/caixanegra/unit.rb
Class Attribute Summary collapse
-
.assignments ⇒ Object
readonly
Returns the value of attribute assignments.
-
.color ⇒ Object
readonly
Returns the value of attribute color.
-
.description ⇒ Object
readonly
Returns the value of attribute description.
-
.exits ⇒ Object
readonly
Returns the value of attribute exits.
-
.inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
.scope ⇒ Object
readonly
Returns the value of attribute scope.
-
.type ⇒ Object
readonly
Returns the value of attribute type.
-
.unit_name ⇒ Object
readonly
Returns the value of attribute unit_name.
Instance Attribute Summary collapse
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
Class Method Summary collapse
- .configure_assignments(assignments) ⇒ Object
- .configure_color(color) ⇒ Object
- .configure_description(value) ⇒ Object
- .configure_exits(exits) ⇒ Object
- .configure_inputs(inputs) ⇒ Object
- .configure_name(value) ⇒ Object
- .configure_scope(value) ⇒ Object
- .configure_type(value) ⇒ Object
Instance Method Summary collapse
- #carry_over(value) ⇒ Object
- #color ⇒ Object
- #current_carry_over ⇒ Object
- #current_storage ⇒ Object
- #description ⇒ Object
- #exit_and_return ⇒ Object
- #exit_through(exit_id) ⇒ Object
- #exits ⇒ Object
- #flow ⇒ Object
-
#initialize(oid, inputs = {}, mappings = {}, carry_over = {}, storage = {}) ⇒ Unit
constructor
A new instance of Unit.
- #input(id) ⇒ Object
- #inputs ⇒ Object
- #persist(value) ⇒ Object
- #scope ⇒ Object
- #set ⇒ Object
- #unit_name ⇒ Object
Constructor Details
#initialize(oid, inputs = {}, mappings = {}, carry_over = {}, storage = {}) ⇒ Unit
Returns a new instance of Unit.
7 8 9 10 11 12 13 14 |
# File 'lib/caixanegra/unit.rb', line 7 def initialize(oid, inputs = {}, mappings = {}, carry_over = {}, storage = {}) @oid = oid @mappings = mappings @inputs = inputs @carry_over = carry_over.with_indifferent_access @storage = storage.with_indifferent_access set_mapping_defaults end |
Class Attribute Details
.assignments ⇒ Object (readonly)
Returns the value of attribute assignments.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def assignments @assignments end |
.color ⇒ Object (readonly)
Returns the value of attribute color.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def color @color end |
.description ⇒ Object (readonly)
Returns the value of attribute description.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def description @description end |
.exits ⇒ Object (readonly)
Returns the value of attribute exits.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def exits @exits end |
.inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def inputs @inputs end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def scope @scope end |
.type ⇒ Object (readonly)
Returns the value of attribute type.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def type @type end |
.unit_name ⇒ Object (readonly)
Returns the value of attribute unit_name.
119 120 121 |
# File 'lib/caixanegra/unit.rb', line 119 def unit_name @unit_name end |
Instance Attribute Details
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
5 6 7 |
# File 'lib/caixanegra/unit.rb', line 5 def oid @oid end |
Class Method Details
.configure_assignments(assignments) ⇒ Object
156 157 158 |
# File 'lib/caixanegra/unit.rb', line 156 def configure_assignments(assignments) @assignments = assignments end |
.configure_color(color) ⇒ Object
160 161 162 |
# File 'lib/caixanegra/unit.rb', line 160 def configure_color(color) @color = color end |
.configure_description(value) ⇒ Object
140 141 142 |
# File 'lib/caixanegra/unit.rb', line 140 def configure_description(value) @description = value end |
.configure_exits(exits) ⇒ Object
148 149 150 |
# File 'lib/caixanegra/unit.rb', line 148 def configure_exits(exits) @exits = exits end |
.configure_inputs(inputs) ⇒ Object
152 153 154 |
# File 'lib/caixanegra/unit.rb', line 152 def configure_inputs(inputs) @inputs = inputs end |
.configure_name(value) ⇒ Object
136 137 138 |
# File 'lib/caixanegra/unit.rb', line 136 def configure_name(value) @unit_name = value end |
.configure_scope(value) ⇒ Object
132 133 134 |
# File 'lib/caixanegra/unit.rb', line 132 def configure_scope(value) @scope = value end |
.configure_type(value) ⇒ Object
144 145 146 |
# File 'lib/caixanegra/unit.rb', line 144 def configure_type(value) @type = value end |
Instance Method Details
#carry_over(value) ⇒ Object
24 25 26 |
# File 'lib/caixanegra/unit.rb', line 24 def carry_over(value) @carry_over.merge!(value) if value.is_a? Hash end |
#color ⇒ Object
103 104 105 |
# File 'lib/caixanegra/unit.rb', line 103 def color self.class.color end |
#current_carry_over ⇒ Object
16 17 18 |
# File 'lib/caixanegra/unit.rb', line 16 def current_carry_over @carry_over.dup end |
#current_storage ⇒ Object
20 21 22 |
# File 'lib/caixanegra/unit.rb', line 20 def current_storage @storage.dup end |
#description ⇒ Object
87 88 89 |
# File 'lib/caixanegra/unit.rb', line 87 def description self.class.description end |
#exit_and_return ⇒ Object
39 40 41 42 43 |
# File 'lib/caixanegra/unit.rb', line 39 def exit_and_return { carry_over: @carry_over } end |
#exit_through(exit_id) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/caixanegra/unit.rb', line 32 def exit_through(exit_id) { exit_through: exit_id, carry_over: @carry_over } end |
#exits ⇒ Object
95 96 97 |
# File 'lib/caixanegra/unit.rb', line 95 def exits self.class.exits || [] end |
#flow ⇒ Object
45 46 47 |
# File 'lib/caixanegra/unit.rb', line 45 def flow exit_through exits.first end |
#input(id) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/caixanegra/unit.rb', line 49 def input(id) = @mappings[id] input_value = case &.[](:type) when 'storage' @storage[id] when 'carryover' @carry_over[id] when 'user' [:value] end if input_value.present? result = input_value.dup input_value.to_s.scan(Regexp.new(/%(.*?)%/)) do |match| match = match[0] result.gsub!("%#{match}%", @carry_over[match] || '') end input_value.to_s.scan(Regexp.new(/@(.*?)@/)) do |match| match = match[0] result.gsub!("@#{match}@", @storage[match] || '') end input_value = result end input_value.presence || @inputs[id][:default] rescue StandardError raise(UnitIOException.new(self), "Unable to fetch input '#{id}'") end |
#inputs ⇒ Object
91 92 93 |
# File 'lib/caixanegra/unit.rb', line 91 def inputs self.class.inputs || [] end |
#persist(value) ⇒ Object
28 29 30 |
# File 'lib/caixanegra/unit.rb', line 28 def persist(value) @storage.merge!(value) if value.is_a? Hash end |
#scope ⇒ Object
79 80 81 |
# File 'lib/caixanegra/unit.rb', line 79 def scope self.class.scope end |
#set ⇒ Object
99 100 101 |
# File 'lib/caixanegra/unit.rb', line 99 def set self.class.set || [] end |
#unit_name ⇒ Object
83 84 85 |
# File 'lib/caixanegra/unit.rb', line 83 def unit_name self.class.unit_name end |