Class: Hieracles::Formats::Csv

Inherits:
Hieracles::Format show all
Defined in:
lib/hieracles/formats/csv.rb

Overview

for db compatibility

Constant Summary collapse

CVS_DELIM =
';'

Instance Method Summary collapse

Methods inherited from Hieracles::Format

#allparams, #initialize, #modules, #params, #show_params

Constructor Details

This class inherits a constructor from Hieracles::Format

Instance Method Details

#build_head(without_common) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/hieracles/formats/csv.rb', line 23

def build_head(without_common)
  output = []
  @node.files(without_common).each do |f|
    output << f
  end
  output += %w(var value overriden)
  make_csv output
end

#build_list(hash, notifications, filter) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/hieracles/formats/csv.rb', line 51

def build_list(hash, notifications, filter)
  if filter[0]
    hash.select! { |k, e| Regexp.new(filter[0]).match k }
  end
  hash.reduce([]) do |a, (k, v)|
    a << make_csv([k, v.join(',')])
    a
  end.join()
end

#build_modules_line(key, value) ⇒ Object



47
48
49
# File 'lib/hieracles/formats/csv.rb', line 47

def build_modules_line(key, value)
  make_csv [key, value]
end

#build_params_line(key, value, filter) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hieracles/formats/csv.rb', line 32

def build_params_line(key, value, filter)
  output = ''
  if !filter || Regexp.new(filter).match(key)
    if value[:overriden]
      output << build_line('-', key, value[:value])
      value[:found_in].each do |v|
        output << build_line(v[:file], key, v[:value], '1')
      end
    else
      output << build_line(value[:file], key, value[:value])
    end
  end
  output
end

#facts(_) ⇒ Object



11
12
13
# File 'lib/hieracles/formats/csv.rb', line 11

def facts(_)
  make_csv(@node.facts.keys) + make_csv(@node.facts.values)
end

#files(_) ⇒ Object



15
16
17
# File 'lib/hieracles/formats/csv.rb', line 15

def files(_)
  make_csv @node.files
end

#info(_) ⇒ Object



7
8
9
# File 'lib/hieracles/formats/csv.rb', line 7

def info(_)
  make_csv @node.info.values
end

#paths(_) ⇒ Object



19
20
21
# File 'lib/hieracles/formats/csv.rb', line 19

def paths(_)
  make_csv @node.paths
end