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.
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
#length ⇒ Object (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 |
#pos ⇒ Object (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 |