Class: PgVerify::Simulation::State
- Inherits:
-
Object
- Object
- PgVerify::Simulation::State
- Defined in:
- lib/pg-verify/simulation/state.rb
Instance Attribute Summary collapse
-
#value_map ⇒ Object
Returns the value of attribute value_map.
Class Method Summary collapse
Instance Method Summary collapse
- #[](var) ⇒ Object
- #[]=(var, value) ⇒ Object
- #clone ⇒ Object
-
#initialize(value_map) ⇒ State
constructor
A new instance of State.
- #names ⇒ Object
- #to_s ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(value_map) ⇒ State
Returns a new instance of State.
17 18 19 |
# File 'lib/pg-verify/simulation/state.rb', line 17 def initialize(value_map) @value_map = value_map end |
Instance Attribute Details
#value_map ⇒ Object
Returns the value of attribute value_map.
6 7 8 |
# File 'lib/pg-verify/simulation/state.rb', line 6 def value_map @value_map end |
Class Method Details
.for_variable_set(var_set) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/pg-verify/simulation/state.rb', line 8 def self.for_variable_set(var_set) value_map = var_set.map { |var| # TODO: Choose random one when nil raise "TODO: Implement this" [var, init_val] }.to_h return self.new(value_map) end |
Instance Method Details
#[](var) ⇒ Object
21 22 23 24 25 |
# File 'lib/pg-verify/simulation/state.rb', line 21 def [](var) var = var.to_sym if var.is_a?(String) var = @value_map.keys.detect { |v| v.name == var } if var.is_a?(Symbol) return @value_map[var] end |
#[]=(var, value) ⇒ Object
27 28 29 30 31 |
# File 'lib/pg-verify/simulation/state.rb', line 27 def []=(var, value) var = var.to_sym if var.is_a?(String) var = @value_map.keys.detect { |v| v.name == var } if var.is_a?(Symbol) @value_map[var] = value end |
#clone ⇒ Object
41 42 43 |
# File 'lib/pg-verify/simulation/state.rb', line 41 def clone() self.class.new(value_map.map { |k, v| [k, v] }.to_h) end |
#names ⇒ Object
37 38 39 |
# File 'lib/pg-verify/simulation/state.rb', line 37 def names() return @value_map.keys.map(&:name) end |
#to_s ⇒ Object
45 46 47 48 49 |
# File 'lib/pg-verify/simulation/state.rb', line 45 def to_s() var_s = @value_map.keys.map(&:name).join("\n") val_s = @value_map.values.join("\n") return var_s.line_combine(val_s, separator: " = ") end |
#variables ⇒ Object
33 34 35 |
# File 'lib/pg-verify/simulation/state.rb', line 33 def variables() return @value_map.keys end |