lib/recite_csv/header/definition.rb in recite_csv-2.0.0 vs lib/recite_csv/header/definition.rb in recite_csv-2.1.0

- old
+ new

@@ -30,10 +30,12 @@ class Hash < Base DEFAULT_CSV_OPTIONS = { headers: :first_row }.freeze class ColumnMethodsBuilder < ::Module def initialize(raw_definition) + super() + raw_definition.each_pair do |method_name, header_name| define_method method_name do self[header_name] end end @@ -46,10 +48,12 @@ end class Array < Base class ColumnMethodsBuilder < ::Module def initialize(raw_definition) + super() + raw_definition.each.with_index do |name, idx| next if name.nil? || name.empty? define_method name do self[idx] @@ -68,12 +72,10 @@ def dispatch(header_definition) _, definition_class = DEFINITIONS.find do |klass, _| header_definition.is_a? klass end - unless definition_class - raise ::ArgumentError, "Unexpected header definition type" - end + raise ::ArgumentError, "Unexpected header definition type" unless definition_class definition_class.new(header_definition) end end end