Class: GodOfThunderSave::StringValue

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos:, length:) ⇒ StringValue

Returns a new instance of StringValue.



5
6
7
8
# File 'lib/god_of_thunder_save/string_value.rb', line 5

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

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



3
4
5
# File 'lib/god_of_thunder_save/string_value.rb', line 3

def length
  @length
end

#posObject (readonly)

Returns the value of attribute pos.



3
4
5
# File 'lib/god_of_thunder_save/string_value.rb', line 3

def pos
  @pos
end

Instance Method Details

#read(file) ⇒ Object



10
11
12
13
14
15
# File 'lib/god_of_thunder_save/string_value.rb', line 10

def read(file)
  file.seek(pos)
  string = file.read(length)

  string.strip
end

#write(file, string) ⇒ Object



17
18
19
20
21
22
# File 'lib/god_of_thunder_save/string_value.rb', line 17

def write(file, string)
  formatted_string = pad_and_truncate(string)

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