Class: HoneyFormat::Configuration
- Inherits:
-
Object
- Object
- HoneyFormat::Configuration
- Defined in:
- lib/honey_format/configuration.rb
Overview
Holds HoneyFormat configuration
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#quote_character ⇒ Object
Returns the value of attribute quote_character.
-
#row_delimiter ⇒ Object
Returns the value of attribute row_delimiter.
-
#skip_lines ⇒ Object
Returns the value of attribute skip_lines.
Instance Method Summary collapse
-
#converter_registry ⇒ #call
Returns the converter registry.
-
#default_converters ⇒ Hash
Default converter registry.
-
#default_header_deduplicators ⇒ Hash
Default header deduplicate strategies.
-
#header_converter ⇒ #call
Returns the header converter.
-
#header_converter=(converter) ⇒ #call
Set the header converter.
-
#header_deduplicator ⇒ #call
Return the deduplication header strategy.
-
#header_deduplicator=(strategy) ⇒ #call
Set the deduplication header strategy.
-
#header_deduplicator_registry ⇒ #call
Returns the column deduplication registry.
-
#initialize ⇒ Configuration
constructor
Instantiate configuration.
Constructor Details
#initialize ⇒ Configuration
Instantiate configuration
15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#delimiter ⇒ Object
Returns the value of attribute delimiter.
12 13 14 |
# File 'lib/honey_format/configuration.rb', line 12 def delimiter @delimiter end |
#quote_character ⇒ Object
Returns the value of attribute quote_character.
12 13 14 |
# File 'lib/honey_format/configuration.rb', line 12 def quote_character @quote_character end |
#row_delimiter ⇒ Object
Returns the value of attribute row_delimiter.
12 13 14 |
# File 'lib/honey_format/configuration.rb', line 12 def row_delimiter @row_delimiter end |
#skip_lines ⇒ Object
Returns the value of attribute skip_lines.
12 13 14 |
# File 'lib/honey_format/configuration.rb', line 12 def skip_lines @skip_lines end |
Instance Method Details
#converter_registry ⇒ #call
Returns the converter registry
93 94 95 |
# File 'lib/honey_format/configuration.rb', line 93 def converter_registry @converter_registry ||= Registry.new(default_converters) end |
#default_converters ⇒ Hash
Default converter registry
99 100 101 |
# File 'lib/honey_format/configuration.rb', line 99 def default_converters @default_converters ||= Converters::DEFAULT end |
#default_header_deduplicators ⇒ Hash
Default header deduplicate strategies
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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? = "all columns must be unique, duplicates are: #{duplicates}" raise(Errors::DuplicateHeaderColumnError, ) end columns end, none: proc { |columns| columns }, }.freeze end |
#header_converter ⇒ #call
Returns the header converter
27 28 29 |
# File 'lib/honey_format/configuration.rb', line 27 def header_converter @header_converter ||= converter_registry[:header_column] end |
#header_converter=(converter) ⇒ #call
Set the header converter
35 36 37 38 39 40 41 |
# 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 ⇒ #call
Return the deduplication header strategy
45 46 47 |
# File 'lib/honey_format/configuration.rb', line 45 def header_deduplicator @header_deduplicator ||= header_deduplicator_registry[:deduplicate] end |
#header_deduplicator=(strategy) ⇒ #call
Set the deduplication header strategy
55 56 57 58 59 60 61 62 63 64 |
# 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 = "unknown deduplication strategy: '#{strategy}'" raise(Errors::UnknownDeduplicationStrategyError, ) end end |
#header_deduplicator_registry ⇒ #call
Returns the column deduplication registry
87 88 89 |
# File 'lib/honey_format/configuration.rb', line 87 def header_deduplicator_registry @header_deduplicator_registry ||= Registry.new(default_header_deduplicators) end |