Class: Inspec::Resources::CsvConfig

Inherits:
JsonConfig show all
Defined in:
lib/resources/csv.rb

Instance Attribute Summary

Attributes inherited from JsonConfig

#params

Instance Method Summary collapse

Methods inherited from JsonConfig

#initialize, #method_missing, #value

Methods included from ObjectTraverser

#extract_value

Constructor Details

This class inherits a constructor from Inspec::Resources::JsonConfig

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Inspec::Resources::JsonConfig

Instance Method Details

#parse(content) ⇒ Object

override file load and parse hash from csv



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/resources/csv.rb', line 19

def parse(content)
  require 'csv'
  # convert empty field to nil
  CSV::Converters[:blank_to_nil] = lambda do |field|
    field && field.empty? ? nil : field
  end
  # implicit conversion of values
  csv = CSV.new(content, headers: true, converters: [:all, :blank_to_nil])
  # convert to hash
  csv.to_a.map(&:to_hash)
end

#to_sObject



31
32
33
# File 'lib/resources/csv.rb', line 31

def to_s
  "Csv #{@path}"
end