class HoneyFormat::Configuration

Holds HoneyFormat configuration @attr_accessor [String] delimiter the default column delimiter (default: ,) @attr_accessor [String, Symbol] row_delimiter the default row delimiter (default: :auto) @attr_accessor [String] quote_character the default quote character (default: “) @attr_accessor [String, Regexp] skip_lines skip all lines matching pattern (default: nil)

Attributes

delimiter[RW]
quote_character[RW]
row_delimiter[RW]
skip_lines[RW]

Public Class Methods

new() click to toggle source

Instantiate configuration

# File lib/honey_format/configuration.rb, line 15
def initialize
  @converter_registry = nil
  @header_converter = nil
  @header_deduplicator = nil
  @delimiter = ','
  @row_delimiter = :auto
  @quote_character = '"'
  @skip_lines = nil
end

Public Instance Methods

converter_registry() click to toggle source

Returns the converter registry @return [#call] converter the configured converter registry

# File lib/honey_format/configuration.rb, line 93
def converter_registry
  @converter_registry ||= Registry.new(default_converters)
end
default_converters() click to toggle source

Default converter registry @return [Hash] hash with default converters

# File lib/honey_format/configuration.rb, line 99
def default_converters
  @default_converters ||= Converters::DEFAULT
end
default_header_deduplicators() click to toggle source

Default header deduplicate strategies @return [Hash] the default header deduplicatation strategies

# File lib/honey_format/configuration.rb, line 68
def default_header_deduplicators
  @default_header_deduplicators ||= {
    deduplicate: proc do |columns|
      Helpers.key_count_to_deduplicated_array(columns)
    end,
    raise: proc do |columns|
      duplicates = Helpers.duplicated_items(columns)
      if duplicates.any?
        message = "all columns must be unique, duplicates are: #{duplicates}"
        raise(Errors::DuplicateHeaderColumnError, message)
      end
      columns
    end,
    none: proc { |columns| columns },
  }.freeze
end
header_converter() click to toggle source

Returns the header converter @return [#call] header_converter the configured header converter

# File lib/honey_format/configuration.rb, line 27
def header_converter
  @header_converter ||= converter_registry[:header_column]
end
header_converter=(converter) click to toggle source

Set the header converter @param [Symbol, call] converter for registered converter registry or object that

responds to #call

@return [#call] the header converter

# File lib/honey_format/configuration.rb, line 35
def header_converter=(converter)
  @header_converter = if converter.is_a?(Symbol)
                        converter_registry[converter]
                      else
                        converter
                      end
end
header_deduplicator() click to toggle source

Return the deduplication header strategy @return [#call] the header deduplication strategy

# File lib/honey_format/configuration.rb, line 45
def header_deduplicator
  @header_deduplicator ||= header_deduplicator_registry[:deduplicate]
end
header_deduplicator=(strategy) click to toggle source

Set the deduplication header strategy @param [Symbol, call]

symbol with known strategy identifier or method that responds
to #call(colums, key_count)

@return [#call] the header deduplication strategy @raise [UnknownDeduplicationStrategyError]

# File lib/honey_format/configuration.rb, line 55
def header_deduplicator=(strategy)
  if header_deduplicator_registry.type?(strategy)
    @header_deduplicator = header_deduplicator_registry[strategy]
  elsif strategy.respond_to?(:call)
    @header_deduplicator = strategy
  else
    message = "unknown deduplication strategy: '#{strategy}'"
    raise(Errors::UnknownDeduplicationStrategyError, message)
  end
end
header_deduplicator_registry() click to toggle source

Returns the column deduplication registry @return [#call] column deduplication registry

# File lib/honey_format/configuration.rb, line 87
def header_deduplicator_registry
  @header_deduplicator_registry ||= Registry.new(default_header_deduplicators)
end