class Elf::Value

Attributes

desc[R]
mnemonic[R]
to_i[R]
to_s[R]
val[R]

Public Class Methods

[](idx) click to toggle source
# File lib/elf/value.rb, line 56
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) click to toggle source
# File lib/elf/value.rb, line 102
def Value.each(&block)
  @enums.each_value(&block)
end
from_string(str) click to toggle source
# File lib/elf/value.rb, line 75
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) click to toggle source
# File lib/elf/value.rb, line 85
def Value.has_key?(idx)
  @enums.has_key?(idx)
end
new(val, params) click to toggle source
# File lib/elf/value.rb, line 42
def initialize(val, params)
  @val = val
  @mnemonic = params[0].to_s
  @desc = params[1]
end

Private Class Methods

fill(*hash) click to toggle source
# File lib/elf/value.rb, line 89
def Value.fill(*hash)
  if hash.size == 1 && hash[0].is_a?(Hash)
    hash = hash[0]
  end

  @enums = { }

  hash.each_pair do |index, value|
    @enums[index] = self.new(index, value)
    const_set(value[0], @enums[index])
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/elf/value.rb, line 52
def ==(other)
  self.class == other.class and @val == other.to_i
end