Class: Sankey::Process
- Inherits:
-
Object
- Object
- Sankey::Process
- Defined in:
- lib/process.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #add_input(reagent, order = nil) ⇒ Object
- #add_output(reagent, order = nil) ⇒ Object
- #fraction(reagent) ⇒ Object
-
#initialize ⇒ Process
constructor
A new instance of Process.
- #is_first_in_input_queue(reagent) ⇒ Object
- #is_first_in_output_queue(reagent) ⇒ Object
- #remove_from_input_queue(reagent) ⇒ Object
- #remove_from_output_queue(reagent) ⇒ Object
- #total_reagents_mass ⇒ Object
Constructor Details
#initialize ⇒ Process
Returns a new instance of Process.
5 6 7 8 9 10 |
# File 'lib/process.rb', line 5 def initialize @input = [] @output = [] @input_reagents_queue = {} @output_reagents_queue = {} end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
3 4 5 |
# File 'lib/process.rb', line 3 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
3 4 5 |
# File 'lib/process.rb', line 3 def output @output end |
Instance Method Details
#add_input(reagent, order = nil) ⇒ Object
30 31 32 33 |
# File 'lib/process.rb', line 30 def add_input(reagent, order = nil) @input.push reagent @input_reagents_queue[order] = reagent unless order.nil? end |
#add_output(reagent, order = nil) ⇒ Object
25 26 27 28 |
# File 'lib/process.rb', line 25 def add_output(reagent, order = nil) @output.push reagent @output_reagents_queue[order] = reagent unless order.nil? end |
#fraction(reagent) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/process.rb', line 12 def fraction(reagent) side = nil [@output, @input].each { |io| side = io if io.include? reagent } throw "Reagent isn't present in this process" if side.nil? sum = 0 side.each { |r| sum += r.size } reagent.size * 1.0 / sum end |
#is_first_in_input_queue(reagent) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process.rb', line 51 def is_first_in_input_queue(reagent) min_key = nil return true unless @input_reagents_queue.values.include? reagent @input_reagents_queue.each do |key, val| #STDERR.puts "#{key} -> #{val.name}" min_key ||= key min_key = [min_key, key].min end @input_reagents_queue[min_key] == reagent end |
#is_first_in_output_queue(reagent) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/process.rb', line 62 def is_first_in_output_queue(reagent) min_key = nil return true unless @output_reagents_queue.values.include? reagent @output_reagents_queue.each do |key, val| min_key ||= key min_key = [min_key, key].min end @output_reagents_queue[min_key] == reagent end |
#remove_from_input_queue(reagent) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/process.rb', line 35 def remove_from_input_queue(reagent) key_to_be_removed = nil @input_reagents_queue.each do |key, val| key_to_be_removed = key if val == reagent end @input_reagents_queue.delete key_to_be_removed end |
#remove_from_output_queue(reagent) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/process.rb', line 43 def remove_from_output_queue(reagent) key_to_be_removed = nil @output_reagents_queue.each do |key, val| key_to_be_removed = key if val == reagent end @output_reagents_queue.delete key_to_be_removed end |
#total_reagents_mass ⇒ Object
21 22 23 |
# File 'lib/process.rb', line 21 def total_reagents_mass check_conservation_of_mass end |