Class: Kanrisuru::Core::Disk::Parser::Blkid

Inherits:
Object
  • Object
show all
Defined in:
lib/kanrisuru/core/disk/parsers/blkid.rb

Class Method Summary collapse

Class Method Details

.parse(command, mode) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kanrisuru/core/disk/parsers/blkid.rb', line 9

def parse(command, mode)
  return command.to_s if mode == 'search'

  lines = command.to_a

  devices = []
  current_device = nil

  lines.each do |line|
    value = line.split('=')[1]

    if line =~ /^DEVNAME=/
      current_device = Kanrisuru::Core::Disk::BlkidDevice.new(value)
    elsif line =~ /^UUID=/
      current_device.uuid = value
    elsif line =~ /^LABEL=/
      current_device.label = value
    elsif line =~ /^TYPE=/
      current_device.type = value
    elsif line =~ /^LABEL_FATBOOT=/
      current_device.label_fatboot = value
    elsif line =~ /^PARTUUID=/
      current_device.part_uuid = value
    elsif line =~ /^UUID_SUB=/
      current_device.uuid_sub = value
    elsif line =~ /^USAGE=/
      current_device.usage = value
    elsif line =~ /^VERSION=/
      current_device.version = value.to_f
    elsif line =~ /^MINIMUM_IO_SIZE=/
      current_device.minimum_io_size = value.to_i
    elsif line =~ /^PHYSICAL_SECTOR_SIZE=/
      current_device.physical_sector_size = value.to_i
    elsif line =~ /^LOGICAL_SECTOR_SIZE=/
      current_device.logical_sector_size = value.to_i
    elsif line =~ /^PART_ENTRY_SCHEME=/
      current_device.part_entry_scheme = value
    elsif line =~ /^PART_ENTRY_UUID=/
      current_device.part_entry_uuid = value
    elsif line =~ /^PART_ENTRY_DISK=/
      current_device.part_entry_disk = value
    elsif line =~ /^PART_ENTRY_NUMBER=/
      current_device.part_entry_number = value.to_i
    elsif line =~ /^PART_ENTRY_OFFSET=/
      current_device.part_entry_offset = value.to_i
    elsif line =~ /^PART_ENTRY_SIZE=/
      current_device.part_entry_size = value.to_i
    elsif line =~ /^PART_ENTRY_TYPE=/
      current_device.part_entry_type = value
    elsif Kanrisuru::Util.blank?(line)
      devices << current_device
      current_device = nil
    end
  end

  devices << current_device if Kanrisuru::Util.present?(current_device)
  devices
end