Class: PgVerify::Model::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/pg-verify/model/variable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_expressionObject

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

#nameObject

Name of this variable as a symbol



7
8
9
# File 'lib/pg-verify/model/variable.rb', line 7

def name
  @name
end

#owner_nameObject

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

#rangeObject

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_locationObject

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.

Returns:

  • (Boolean)


39
40
41
# File 'lib/pg-verify/model/variable.rb', line 39

def state_variable?()
    return @name == @owner_name
end

#valuesObject

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