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.



7
8
9
10
# File 'lib/god_of_thunder_save/string_value.rb', line 7

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

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



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

def length
  @length
end

#posObject (readonly)

Returns the value of attribute pos.



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

def pos
  @pos
end

Instance Method Details

#read(file) ⇒ Object



12
13
14
15
16
17
# File 'lib/god_of_thunder_save/string_value.rb', line 12

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

  string.strip
end

#write(file, string) ⇒ Object



19
20
21
22
23
24
# File 'lib/god_of_thunder_save/string_value.rb', line 19

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

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