Class: Solve::Solver::VariableTable
- Inherits:
-
Object
- Object
- Solve::Solver::VariableTable
- Defined in:
- lib/solve/solver/variable_table.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #add(artifact, source) ⇒ Object
- #all_after(artifact) ⇒ Object
- #all_from_source(source) ⇒ Object
- #before(artifact) ⇒ Object
- #find_artifact(artifact) ⇒ Object
- #first_unbound ⇒ Object
-
#initialize ⇒ VariableTable
constructor
A new instance of VariableTable.
- #remove_all_with_only_this_source!(source) ⇒ Object
Constructor Details
#initialize ⇒ VariableTable
Returns a new instance of VariableTable.
6 7 8 |
# File 'lib/solve/solver/variable_table.rb', line 6 def initialize @rows = Array.new end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/solve/solver/variable_table.rb', line 4 def rows @rows end |
Instance Method Details
#add(artifact, source) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/solve/solver/variable_table.rb', line 12 def add(artifact, source) row = rows.detect { |row| row.artifact == artifact } if row.nil? @rows << VariableRow.new(artifact, source) else row.add_source(source) end end |
#all_after(artifact) ⇒ Object
49 50 51 52 |
# File 'lib/solve/solver/variable_table.rb', line 49 def all_after(artifact) artifact_index = @rows.index { |row| row.artifact == artifact } @rows[(artifact_index+1)..-1] end |
#all_from_source(source) ⇒ Object
38 39 40 |
# File 'lib/solve/solver/variable_table.rb', line 38 def all_from_source(source) @rows.select { |row| row.sources.include?(source) } end |
#before(artifact) ⇒ Object
43 44 45 46 |
# File 'lib/solve/solver/variable_table.rb', line 43 def before(artifact) artifact_index = @rows.index { |row| row.artifact == artifact } (artifact_index == 0) ? nil : @rows[artifact_index - 1] end |
#find_artifact(artifact) ⇒ Object
26 27 28 |
# File 'lib/solve/solver/variable_table.rb', line 26 def find_artifact(artifact) @rows.detect { |row| row.artifact == artifact } end |
#first_unbound ⇒ Object
21 22 23 |
# File 'lib/solve/solver/variable_table.rb', line 21 def first_unbound @rows.detect { |row| row.bound? == false } end |
#remove_all_with_only_this_source!(source) ⇒ Object
31 32 33 34 35 |
# File 'lib/solve/solver/variable_table.rb', line 31 def remove_all_with_only_this_source!(source) with_only_this_source, others = @rows.partition { |row| row.sources == [source] } @rows = others with_only_this_source end |