class Origen::Value

This class wraps various different class which handle number representation in various formats.

The user should never instantiate those directly and should always instantiate an Origen::Value instance, thereby ensuring a common API regardless of the internal representation and handling of the value

Public Class Methods

new(val, options = {}) click to toggle source
# File lib/origen/value.rb, line 48
def initialize(val, options = {})
  if val.is_a?(Integer)
    @val = val
  else
    val = val.to_s
    case val[0].downcase
    when 'b'
      @val = BinStrVal.new(val, options)
    when 'h'
      @val = HexStrVal.new(val, options)
    when 'd'
      @val = val.to_s[1..-1].to_i
    else
      if val =~ /^[0-9]+$/
        @val = val.to_i
      else
        fail 'Unsupported value syntax'
      end
    end
  end
end

Public Instance Methods

[](index) click to toggle source
# File lib/origen/value.rb, line 106
def [](index)
  if index.is_a?(Range)
    fail 'Currently, only single bit extraction from a Value object is supported'
  end

  val[index]
end
bin_str_val?() click to toggle source
# File lib/origen/value.rb, line 101
def bin_str_val?
  val.is_a?(BinStrVal)
end
Also aliased as: bin_str_value?
bin_str_value?()
Alias for: bin_str_val?
bits()
Alias for: size
hex_str_val?() click to toggle source
# File lib/origen/value.rb, line 96
def hex_str_val?
  val.is_a?(HexStrVal)
end
Also aliased as: hex_str_value?
hex_str_value?()
Alias for: hex_str_val?
number_of_bits()
Alias for: size
numeric?() click to toggle source

Returns true if all bits have a numeric value - i.e. no X or Z

# File lib/origen/value.rb, line 71
def numeric?
  val.numeric?
end
size() click to toggle source

Returns the size of the value in bits

# File lib/origen/value.rb, line 90
def size
  val.size
end
Also aliased as: bits, number_of_bits
to_i() click to toggle source

Converts to an integer, returns nil if the value contains non-numeric bits

# File lib/origen/value.rb, line 80
def to_i
  val.to_i
end
to_s() click to toggle source

Converts to a string, the format of it depends on the underlying value type

# File lib/origen/value.rb, line 85
def to_s
  val.to_s
end
value?() click to toggle source
# File lib/origen/value.rb, line 75
def value?
  true
end

Private Instance Methods

val() click to toggle source
# File lib/origen/value.rb, line 116
def val
  @val
end