Class: SMPTool::VirtualVolume::Volume
- Inherits:
-
Object
- Object
- SMPTool::VirtualVolume::Volume
- Extended by:
- Forwardable
- Defined in:
- lib/smp_tool/virtual_volume/volume.rb
Overview
Ruby representation of the volume.
Instance Attribute Summary collapse
-
#bootloader ⇒ Object
readonly
Returns the value of attribute bootloader.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#home_block ⇒ Object
readonly
Returns the value of attribute home_block.
-
#volume_params ⇒ Object
readonly
Returns the value of attribute volume_params.
Class Method Summary collapse
Instance Method Summary collapse
-
#f_delete(filename) ⇒ String
Delete a file.
-
#f_extract_raw(filename) ⇒ FileInterface
Extract content of a file as a ‘raw’ string (as is).
-
#f_extract_raw_all ⇒ Array<FileInterface>
Extract all files as ‘raw’ strings.
-
#f_extract_txt(filename) {|str| ... } ⇒ FileInterface
Extract content of a file as an array of strings.
-
#f_extract_txt_all ⇒ Array<FileInterface>
Extract all files as arrays of strings.
-
#f_push(file_obj) {|str| ... } ⇒ String
Push a file to the volume.
-
#f_rename(old_filename, new_filename) ⇒ Array<String>
Rename a file.
-
#initialize(bootloader:, home_block:, volume_params:, volume_data: nil) ⇒ Volume
constructor
Create new virtual volume.
-
#resize(n_clusters) ⇒ Integer
Allocate more clusters to the volume or trim free clusters.
- #snapshot ⇒ Object
-
#squeeze ⇒ Integer
Consolidate all free space at the end ot the volume.
-
#to_binary_s ⇒ String
Convert ‘self` to a binary string.
-
#to_volume_io ⇒ VolumeIO
Convert ‘self` to a VolumeIO object.
Constructor Details
#initialize(bootloader:, home_block:, volume_params:, volume_data: nil) ⇒ Volume
Create new virtual volume.
35 36 37 38 39 40 41 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 35 def initialize(bootloader:, home_block:, volume_params:, volume_data: nil) @bootloader = bootloader @home_block = home_block @volume_params = volume_params @data = volume_data || Utils::EmptyVolDataInitializer.call(@volume_params) end |
Instance Attribute Details
#bootloader ⇒ Object (readonly)
Returns the value of attribute bootloader.
14 15 16 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 14 def bootloader @bootloader end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 14 def data @data end |
#home_block ⇒ Object (readonly)
Returns the value of attribute home_block.
14 15 16 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 14 def home_block @home_block end |
#volume_params ⇒ Object (readonly)
Returns the value of attribute volume_params.
14 15 16 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 14 def volume_params @volume_params end |
Class Method Details
.read_io(volume_io) ⇒ Object
20 21 22 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 20 def self.read_io(volume_io) Utils::ConverterFromVolumeIO.read_io(volume_io) end |
.read_volume_io(volume_io) ⇒ Object
16 17 18 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 16 def self.read_volume_io(volume_io) Utils::ConverterFromVolumeIO.read_volume_io(volume_io) end |
Instance Method Details
#f_delete(filename) ⇒ String
Delete a file.
188 189 190 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 188 def f_delete(filename) @data.f_delete(Filename.new(ascii: filename)) end |
#f_extract_raw(filename) ⇒ FileInterface
Extract content of a file as a ‘raw’ string (as is).
149 150 151 152 153 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 149 def f_extract_raw(filename) Utils::FileExtracter.new(@data).f_extract_raw( Filename.new(ascii: filename) ) end |
#f_extract_raw_all ⇒ Array<FileInterface>
Extract all files as ‘raw’ strings.
160 161 162 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 160 def f_extract_raw_all _all_filenames.map { |fn| f_extract_raw(fn) } end |
#f_extract_txt(filename) {|str| ... } ⇒ FileInterface
Extract content of a file as an array of strings.
123 124 125 126 127 128 129 130 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 123 def f_extract_txt(filename, &block) block = ->(str) { InjalidDejice.koi_to_utf(str) } unless block_given? Utils::FileExtracter.new(@data).f_extract_txt( Filename.new(ascii: filename), &block ) end |
#f_extract_txt_all ⇒ Array<FileInterface>
Extract all files as arrays of strings.
137 138 139 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 137 def f_extract_txt_all _all_filenames.map { |fn| f_extract_txt(fn) } end |
#f_push(file_obj) {|str| ... } ⇒ String
Push a file to the volume.
104 105 106 107 108 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 104 def f_push(file_obj, &block) block = ->(str) { InjalidDejice.utf_to_koi(str, forced_latin: "\"") } unless block_given? _f_push(file_obj, &block) end |
#f_rename(old_filename, new_filename) ⇒ Array<String>
Rename a file.
173 174 175 176 177 178 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 173 def f_rename(old_filename, new_filename) @data.f_rename( Filename.new(ascii: old_filename), Filename.new(ascii: new_filename) ) end |
#resize(n_clusters) ⇒ Integer
Allocate more clusters to the volume or trim free clusters.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 79 def resize(n_clusters) if n_clusters.positive? _resize_validate_pos_input(n_clusters) elsif n_clusters.negative? _resize_validate_neg_input(n_clusters) else return n_clusters end _resize(n_clusters) end |
#snapshot ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 43 def snapshot { volume_params: @volume_params.snapshot, volume_data: @data.snapshot, n_free_clusters: @data.calc_n_free_clusters } end |
#squeeze ⇒ Integer
Consolidate all free space at the end ot the volume.
198 199 200 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 198 def squeeze @data.squeeze end |
#to_binary_s ⇒ String
Convert ‘self` to a binary string. Write this string to a binary file to get a MK90 volume that works on an emulator or on a real machine.
66 67 68 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 66 def to_binary_s to_volume_io.to_binary_s end |
#to_volume_io ⇒ VolumeIO
Convert ‘self` to a VolumeIO object.
56 57 58 |
# File 'lib/smp_tool/virtual_volume/volume.rb', line 56 def to_volume_io Utils::ConverterToVolumeIO.new(self).call end |