Class: Rips::Variables::Variable
- Inherits:
-
Object
- Object
- Rips::Variables::Variable
- Defined in:
- lib/rips/variables/variable.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
-
#between?(value, range) ⇒ Boolean
Check if value is between in permitted range.
-
#error(value) ⇒ Object
Return error message about incorrent syntax.
-
#initialize(length) ⇒ Variable
constructor
A new instance of Variable.
-
#number?(value) ⇒ Boolean
Check if value is a valid number (…,-1,0,1…).
-
#port?(value) ⇒ Boolean
Check if value is a port (@0..3).
-
#register?(value) ⇒ Boolean
Check if value is a register ($0..15).
-
#to_i(value) ⇒ Object
Return integer part of value.
Constructor Details
#initialize(length) ⇒ Variable
Returns a new instance of Variable.
9 10 11 |
# File 'lib/rips/variables/variable.rb', line 9 def initialize (length) @length = length end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/rips/variables/variable.rb', line 6 def length @length end |
Instance Method Details
#between?(value, range) ⇒ Boolean
Check if value is between in permitted range
29 30 31 |
# File 'lib/rips/variables/variable.rb', line 29 def between? (value, range) to_i(value).between?(range[0], range[1]) end |
#error(value) ⇒ Object
Return error message about incorrent syntax
39 40 41 |
# File 'lib/rips/variables/variable.rb', line 39 def error (value) "unexpected `#{value}` (expected a `#{self.class.to_s.split(':').last}` argument like `#{@syntax}`)" end |
#number?(value) ⇒ Boolean
Check if value is a valid number (…,-1,0,1…)
24 25 26 |
# File 'lib/rips/variables/variable.rb', line 24 def number? (value) /\A[-]?\d+\z/ === value end |
#port?(value) ⇒ Boolean
Check if value is a port (@0..3)
19 20 21 |
# File 'lib/rips/variables/variable.rb', line 19 def port? (value) (value[0] == "@") && number?(value.slice(1..-1)) end |
#register?(value) ⇒ Boolean
Check if value is a register ($0..15)
14 15 16 |
# File 'lib/rips/variables/variable.rb', line 14 def register? (value) (value[0] == "$") && number?(value.slice(1..-1)) end |
#to_i(value) ⇒ Object
Return integer part of value
34 35 36 |
# File 'lib/rips/variables/variable.rb', line 34 def to_i (value) number?(value) ? value.to_i : value.slice(1..-1).to_i end |