Class: Rips::Variables::Port

Inherits:
Variable show all
Defined in:
lib/rips/variables/port.rb

Instance Attribute Summary collapse

Attributes inherited from Variable

#length

Instance Method Summary collapse

Methods inherited from Variable

#between?, #error, #number?, #port?, #register?, #to_i

Constructor Details

#initialize(size = 2) ⇒ Port

@syntax: example syntax @range: bit’s range for variable



12
13
14
15
16
17
# File 'lib/rips/variables/port.rb', line 12

def initialize(size = 2)
  super(size)
  @syntax = "@0-3"
  @range = [0, 2**@length-1]
  @syntax = "@#{@range[0]}-#{@range[1]}"
end

Instance Attribute Details

#syntaxObject (readonly)

Returns the value of attribute syntax.



8
9
10
# File 'lib/rips/variables/port.rb', line 8

def syntax
  @syntax
end

Instance Method Details

#syntax?(value) ⇒ Boolean

Check input variable syntax

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/rips/variables/port.rb', line 20

def syntax? (value)

  # It should be between syntax range
  if port?(value) && between?(value, @range)
    true
  else
    false
  end       
end