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
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
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
Source
# File lib/origen/value.rb, line 101 def bin_str_val? val.is_a?(BinStrVal) end
Also aliased as: bin_str_value?
Source
# File lib/origen/value.rb, line 96 def hex_str_val? val.is_a?(HexStrVal) end
Also aliased as: hex_str_value?
Source
Source
# File lib/origen/value.rb, line 90 def size val.size end
Returns the size of the value in bits
Also aliased as: bits, number_of_bits
Source
# File lib/origen/value.rb, line 80 def to_i val.to_i end
Converts to an integer, returns nil if the value contains non-numeric bits
Source
# File lib/origen/value.rb, line 85 def to_s val.to_s end
Converts to a string, the format of it depends on the underlying value type