class SimpleCsv::Settings
Constants
- ALIASSED
- DEFAULTS
- INVERTED_ALIASSES
Public Class Methods
new(**opts)
click to toggle source
# File lib/simple_csv/settings.rb, line 9 def initialize(**opts) @settings = DEFAULTS.dup.merge opts end
Public Instance Methods
[](setting)
click to toggle source
# File lib/simple_csv/settings.rb, line 13 def [](setting) send setting end
[]=(m, val)
click to toggle source
# File lib/simple_csv/settings.rb, line 17 def []=(m, val) @settings[m] = val return @settings[ALIASSED[m]] = val if ALIASSED.key? m return @settings[INVERTED_ALIASSES[m]] = val if INVERTED_ALIASSES.key? m val end
accepted_method?(mtd)
click to toggle source
# File lib/simple_csv/settings.rb, line 55 def accepted_method?(mtd) @settings.key?(mtd) || ALIASSED.key?(mtd) || INVERTED_ALIASSES.key?(mtd) end
any?()
click to toggle source
# File lib/simple_csv/settings.rb, line 40 def any? @settings && @settings.any? end
apply(*hashes)
click to toggle source
# File lib/simple_csv/settings.rb, line 36 def apply(*hashes) hashes.each { |opts| opts.each { |k, v| self[k] = v } } && @settings end
for_csv()
click to toggle source
# File lib/simple_csv/settings.rb, line 24 def for_csv settings = @settings.dup ALIASSED.each do |opt_alias, opt| settings[opt] = settings.delete(opt_alias) if settings.key? opt_alias end CSV::DEFAULT_OPTIONS.each_with_object({}) do |(prop, default), csv_hash| csv_hash[prop] = settings.key?(prop) ? settings[prop] : default end end
method_missing(mtd, *args, &block)
click to toggle source
Calls superclass method
# File lib/simple_csv/settings.rb, line 48 def method_missing(mtd, *args, &block) return super unless accepted_method? mtd mtd = ALIASSED[mtd] if ALIASSED.key? mtd mtd = INVERTED_ALIASSES[mtd] if INVERTED_ALIASSES.key? mtd @settings[mtd] end
respond_to_missing?(mtd, include_private = false)
click to toggle source
Calls superclass method
# File lib/simple_csv/settings.rb, line 44 def respond_to_missing?(mtd, include_private = false) accepted_method? mtd || super end