Class: PgVerify::Model::Variable
- Inherits:
-
Object
- Object
- PgVerify::Model::Variable
- Defined in:
- lib/pg-verify/model/variable.rb
Instance Attribute Summary collapse
-
#init_expression ⇒ Object
An expression to be used to initialize this variable While this can be something simple like “my_var = 10”, it can also be something more involved like “my_var > 10 && my_var < 15”.
-
#name ⇒ Object
Name of this variable as a symbol.
-
#owner_name ⇒ Object
The name of the component which owns this variable as a symbol.
-
#range ⇒ Object
Range of this variable.
-
#source_location ⇒ Object
The location in source, where this variable was defined.
Instance Method Summary collapse
-
#initialize(name, range, owner_name, source_location, init: nil) ⇒ Variable
constructor
A new instance of Variable.
-
#state_variable? ⇒ Boolean
A state variable represents the states of a component.
-
#values ⇒ Object
Returns all possible values of this variable as an array.
Constructor Details
#initialize(name, range, owner_name, source_location, init: nil) ⇒ Variable
Returns a new instance of Variable.
25 26 27 28 29 |
# File 'lib/pg-verify/model/variable.rb', line 25 def initialize(name, range, owner_name, source_location, init: nil) init = Model::ParsedExpression.new(init, Model::ParsedExpression::TYPE_PL) if init.is_a?(String) @name, @range, @owner_name, @init_expression = name, range, owner_name, init @source_location = source_location end |
Instance Attribute Details
#init_expression ⇒ Object
An expression to be used to initialize this variable While this can be something simple like “my_var = 10”, it can also be something more involved like “my_var > 10 && my_var < 15”.
20 21 22 |
# File 'lib/pg-verify/model/variable.rb', line 20 def init_expression @init_expression end |
#name ⇒ Object
Name of this variable as a symbol
7 8 9 |
# File 'lib/pg-verify/model/variable.rb', line 7 def name @name end |
#owner_name ⇒ Object
The name of the component which owns this variable as a symbol
10 11 12 |
# File 'lib/pg-verify/model/variable.rb', line 10 def owner_name @owner_name end |
#range ⇒ Object
Range of this variable. This can either be a range like (0..2) an array of numbers like [0, 1, 2] or an array of symbols representing states of components like [:Idle, :Breaking]
15 16 17 |
# File 'lib/pg-verify/model/variable.rb', line 15 def range @range end |
#source_location ⇒ Object
The location in source, where this variable was defined
23 24 25 |
# File 'lib/pg-verify/model/variable.rb', line 23 def source_location @source_location end |
Instance Method Details
#state_variable? ⇒ Boolean
A state variable represents the states of a component. e.g: Switch with range [:on, :off] for component switch.
39 40 41 |
# File 'lib/pg-verify/model/variable.rb', line 39 def state_variable?() return @name == @owner_name end |
#values ⇒ Object
Returns all possible values of this variable as an array
32 33 34 35 |
# File 'lib/pg-verify/model/variable.rb', line 32 def values() return @range if @range.is_a?(Array) return @range.to_a end |