Class: GodOfThunderSave::StringValue
- Inherits:
-
Object
- Object
- GodOfThunderSave::StringValue
- Defined in:
- lib/god_of_thunder_save/string_value.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#initialize(pos:, length:) ⇒ StringValue
constructor
A new instance of StringValue.
- #read(file) ⇒ Object
- #write(file, string) ⇒ Object
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
#length ⇒ Object (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 |
#pos ⇒ Object (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 |