Class: Arcana::Offset
- Inherits:
-
Object
- Object
- Arcana::Offset
- Defined in:
- lib/arcana.rb
Instance Method Summary collapse
- #exact? ⇒ Boolean
- #indirect? ⇒ Boolean
-
#initialize(str) ⇒ Offset
constructor
A new instance of Offset.
- #position(input) ⇒ Object
- #relative? ⇒ Boolean
- #seek(input) ⇒ Object
- #to_s ⇒ Object
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_s ⇒ Object
96 97 98 |
# File 'lib/arcana.rb', line 96 def to_s @str end |