Class: Arcana::Offset

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

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Offset



60
61
62
# File 'lib/arcana.rb', line 60

def initialize(str)
  @str = str
end

Instance Method Details

#exact?Boolean



64
65
66
# File 'lib/arcana.rb', line 64

def exact?
  @str.match?(/\A(?:-?[0-9]+|0x[0-9a-fA-F]+)\z/)
end

#indirect?Boolean



68
69
70
# File 'lib/arcana.rb', line 68

def indirect?
  @str.start_with?("(")
end

#position(input) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/arcana.rb', line 82

def position(input)
  if exact?
    Integer(@str)
  elsif indirect?
    @str.match(/\A\(([0-9]+|0x[0-9a-fA-F]+)([.,])([bBcCeEfFgGhHiIlLmsSqQ])([+-](?:[0-9]+|0x[0-9a-fA-F]+))?\)\z/) || return
    add = $4 ? Integer($4) : 0
    value = read_indirect(input, offset: Integer($1), signed: ($2 == ","), type: $3)
    return unless value # fixme
    value + add
  else
    binding.irb
  end
end

#relative?Boolean



72
73
74
# File 'lib/arcana.rb', line 72

def relative?
  @str.start_with?("&")
end

#seek(input) ⇒ Object



76
77
78
79
80
# File 'lib/arcana.rb', line 76

def seek(input)
  pos = position(input)
  return if pos.nil? # FIXME: raise?
  input.seek_pos(pos)
end

#to_sObject



96
97
98
# File 'lib/arcana.rb', line 96

def to_s
  @str
end