Class: Inspec::Resources::CsvConfig
- Inherits:
-
JsonConfig
- Object
- JsonConfig
- Inspec::Resources::CsvConfig
- Defined in:
- lib/resources/csv.rb
Instance Attribute Summary
Attributes inherited from JsonConfig
Instance Method Summary collapse
-
#parse(content) ⇒ Object
override file load and parse hash from csv.
- #to_s ⇒ Object
Methods inherited from JsonConfig
#initialize, #method_missing, #value
Methods included from ObjectTraverser
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_s ⇒ Object
31 32 33 |
# File 'lib/resources/csv.rb', line 31 def to_s "Csv #{@path}" end |