Class: GodOfThunderSave::IntegerValue

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

Constant Summary collapse

INTEGER_DIRECTIVES =
{
  1 => "C",
  2 => "v",
  4 => "V"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos:, bytes:) ⇒ IntegerValue

Returns a new instance of IntegerValue.



13
14
15
16
# File 'lib/god_of_thunder_save/integer_value.rb', line 13

def initialize(pos:, bytes:)
  @pos = pos
  @bytes = bytes
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



11
12
13
# File 'lib/god_of_thunder_save/integer_value.rb', line 11

def bytes
  @bytes
end

#posObject (readonly)

Returns the value of attribute pos.



11
12
13
# File 'lib/god_of_thunder_save/integer_value.rb', line 11

def pos
  @pos
end

Instance Method Details

#read(file) ⇒ Object



18
19
20
21
22
23
# File 'lib/god_of_thunder_save/integer_value.rb', line 18

def read(file)
  file.seek(pos)

  bytes_read = file.read(bytes)
  bytes_read.unpack(integer_directive).first
end

#write(file, data) ⇒ Object



25
26
27
28
29
30
# File 'lib/god_of_thunder_save/integer_value.rb', line 25

def write(file, data)
  bytes_write = [data].pack(integer_directive)

  file.seek(pos)
  file.write(bytes_write)
end