Class: SMPTool::VirtualVolume::Volume

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/smp_tool/virtual_volume/volume.rb

Overview

Ruby representation of the volume.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bootloaderObject (readonly)

Returns the value of attribute bootloader.



14
15
16
# File 'lib/smp_tool/virtual_volume/volume.rb', line 14

def bootloader
  @bootloader
end

#dataObject (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_blockObject (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_paramsObject (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_allArray<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.

Yields:

  • (str)

    Each line of a file gets passed through this block. The default block decodes a string from the KOI-7 to the UTF-8, but a custom block allows to alter this behavior.



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_allArray<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.

Yields:

  • (str)

    Each line of a file gets passed through this block. The default block encodes a string from the UTF-8 to the KOI-7, but a custom block allows to alter this behavior (e.g. when the file is already in the KOI-7 encoding).



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

#snapshotObject



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

#squeezeInteger

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_sString

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_ioVolumeIO

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