Module: CFA::Grub2::InstallDeviceParser

Defined in:
lib/cfa/grub2/install_device.rb

Overview

specific parser for install devices. File format is easy element per line without comments. for better readability special values generic_mbr and activate is at the end of file

Class Method Summary collapse

Class Method Details

.emptyObject



34
35
36
# File 'lib/cfa/grub2/install_device.rb', line 34

def self.empty
  []
end

.parse(string) ⇒ Object

returns list of non-empty lines



13
14
15
# File 'lib/cfa/grub2/install_device.rb', line 13

def self.parse(string)
  string.lines.map(&:strip).delete_if(&:empty?)
end

.serialize(data) ⇒ Object

gets list of devices and create file content from it



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cfa/grub2/install_device.rb', line 18

def self.serialize(data)
  # do not modify original data as serialize is not end of world
  data = data.dup

  activate = data.delete("activate")
  generic_mbr = data.delete("generic_mbr")

  res = data.join("\n")
  res << "\n" unless res.empty?

  res << "activate\n" if activate
  res << "generic_mbr\n" if generic_mbr

  res
end