Class: Elf::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/elf/value.rb

Defined Under Namespace

Classes: OutOfBound, Unknown

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val, params) ⇒ Value

Returns a new instance of Value.



43
44
45
46
47
# File 'lib/elf/value.rb', line 43

def initialize(val, params)
  @val = val
  @mnemonic = params[0].to_s
  @desc = params[1]
end

Instance Attribute Details

#descObject (readonly) Also known as: to_s

Returns the value of attribute desc.



49
50
51
# File 'lib/elf/value.rb', line 49

def desc
  @desc
end

#mnemonicObject (readonly)

Returns the value of attribute mnemonic.



49
50
51
# File 'lib/elf/value.rb', line 49

def mnemonic
  @mnemonic
end

#valObject (readonly) Also known as: to_i

Returns the value of attribute val.



49
50
51
# File 'lib/elf/value.rb', line 49

def val
  @val
end

Class Method Details

.[](idx) ⇒ Object

Raises:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/elf/value.rb', line 57

def Value.[](idx)
  return @enums[idx] if @enums[idx]

  # If the class has defined special ranges, handle them; a
  # special range is a range of values for which unknown values
  # are allowed (because they are bound to specific usage we don't
  # know about — where on the other hand unknown values outside of
  # these ranges are frown upon); different type of values have
  # different special ranges, each with its own base name, so
  # leave that to be decided by the class itself.
  if self.const_defined?("SpecialRanges")
    self::SpecialRanges.each_pair do |base, range|
      return self::Unknown.new(idx, sprintf("%s+%07x", base, idx-range.first)) if range.include? idx
    end
  end

  raise OutOfBound.new(idx)
end

.each(&block) ⇒ Object



103
104
105
# File 'lib/elf/value.rb', line 103

def Value.each(&block)
  @enums.each_value(&block)
end

.from_string(str) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/elf/value.rb', line 76

def Value.from_string(str)
  str = str.downcase

  each do |value|
    return value if value.mnemonic.downcase == str
  end

  return nil
end

.has_key?(idx) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/elf/value.rb', line 86

def Value.has_key?(idx)
  @enums.has_key?(idx)
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/elf/value.rb', line 53

def ==(other)
  self.class == other.class and @val == other.to_i
end