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



32
33
34
# File 'lib/cfa/grub2/install_device.rb', line 32

def self.empty
  []
end

.parse(string) ⇒ Object

returns list of non-empty lines



11
12
13
# File 'lib/cfa/grub2/install_device.rb', line 11

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



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

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