lib/meibo/data_model.rb in meibo-0.16.0 vs lib/meibo/data_model.rb in meibo-0.17.0
- old
+ new
@@ -1,25 +1,22 @@
# frozen_string_literal: true
-require 'csv'
+require "csv"
module Meibo
module DataModel
module ClassMethods
def parse(csv)
return to_enum(:parse, csv) unless block_given?
actual_headers = CSV.parse_line(csv)
missing_headers = header_fields - actual_headers
- unless missing_headers.empty?
- raise MissingHeadersError, "missing headers: #{missing_headers.join(',')}"
- end
- unless actual_headers.take(header_fields.size) == header_fields
- raise ScrambledHeadersError
- end
+ raise MissingHeadersError, "missing headers: #{missing_headers.join(",")}" unless missing_headers.empty?
+ raise ScrambledHeadersError unless actual_headers.take(header_fields.size) == header_fields
- CSV.parse(csv, encoding: Meibo::CSV_ENCODING, headers: true, converters: parser_converters, header_converters: header_converters).each do |row|
+ CSV.parse(csv, encoding: Meibo::CSV_ENCODING, headers: true, converters: parser_converters,
+ header_converters: header_converters).each do |row|
yield new(**row.to_h)
end
end
end
@@ -76,10 +73,10 @@
def deconstruct_keys(_keys)
to_h
end
def to_a
- self.class.attribute_names.map {|attribute| public_send(attribute) }
+ self.class.attribute_names.map { |attribute| public_send(attribute) }
end
def to_h
self.class.attribute_names.zip(to_a).to_h
end