Module: LVM::Wrapper::Reporting

Includes:
Constants
Included in:
LVS, LVSSEG, PVS, PVSSEG, VGS
Defined in:
lib/lvm/wrapper.rb,
lib/lvm/wrapper/constants.rb

Defined Under Namespace

Modules: Constants

Constant Summary

Constants included from Constants

Constants::BASE_ARGUMENTS, Constants::EMPTY, Constants::SEPERATOR

Class Method Summary collapse

Class Method Details

.build_command(expected_attributes, base, additional_arguments = []) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lvm/wrapper.rb', line 41

def build_command(expected_attributes, base, additional_arguments = [])
  opts = []
  expected_attributes.each do |a|
    opts << a[:column]
  end

  additional_arguments = [] if additional_arguments.nil?
  additional_arguments = [additional_arguments] if additional_arguments.is_a?(String)

  return base % opts.join(",") + "#{additional_arguments.empty? ? '' : ' '}#{additional_arguments.join(' ')}"
end

.process_line(expected_attributes, line) ⇒ Object

Breakdown return values into attribute => value hash suitable for OpenStruct



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
# File 'lib/lvm/wrapper.rb', line 12

def process_line(expected_attributes, line) #:nodoc:
  line.strip!
  values = line.split(SEPERATOR)
  # nil is easier
  values.map! { |v| (v.empty?) ? nil : v }

  attributes = {}
  # values and expected attributes are in the same order
  values.size.times do |i|
    value = values[i]
    attribute = expected_attributes[i]

    name = attribute[:method].to_sym

    # use hints for type conversion
    case attribute[:type_hint]
    when "String"
    when "Integer"
      value = value.to_i
    when "Float"
      value = value.to_f
    end
    attributes[name] = value
  end

  return attributes
end