class CsvShaper::Config
Config
Configure the standard CSV default options as well the option to output the header row
Constants
- CUSTOM_DEFAULT_OPTIONS
Attributes
Public Class Methods
Source
# File lib/csv_shaper/config.rb, line 13 def initialize @options = {} @options.merge!(CUSTOM_DEFAULT_OPTIONS) yield self if block_given? end
Public Instance Methods
Source
# File lib/csv_shaper/config.rb, line 21 def method_missing(meth, value) meth = sanitize_setter_method(meth) if defaults.key?(meth) @options[meth] = value else super end end
Public: set options where the method name matches a key
Calls superclass method
Source
# File lib/csv_shaper/config.rb, line 31 def respond_to?(meth) meth = sanitize_setter_method(meth) defaults.key?(meth) end
Private Instance Methods
Source
# File lib/csv_shaper/config.rb, line 53 def defaults @defaults ||= CSV::DEFAULT_OPTIONS.dup. merge(write_headers: true). merge(CUSTOM_DEFAULT_OPTIONS) end
Internal: default CSV options, plus a write headers option, to pass to to_csv
Returns a Hash
Source
# File lib/csv_shaper/config.rb, line 44 def sanitize_setter_method(meth) meth = meth.to_s.gsub('=', '') meth.to_sym end
Internal: removes the equals from the end of the method name
‘meth` - Symbol of the method of sanitize
Returns a Symbol