Sha256: 83cbd5df60b09bebee2a206e73b714c693482e6b19a7ce4b2c93ac844014b7f1
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require "csv" module Decidim module DirectVerifications module Parsers class MetadataParser < BaseParser I18N_SCOPE = "decidim.direct_verifications.verification.admin.direct_verifications" def header @header ||= begin raise InputParserError, I18n.t("#{I18N_SCOPE}.create.missing_header") if lines.count <= 1 tokenize(lines[0].chomp).map { |h| h.to_s.downcase } end end def lines @lines ||= StringIO.new(txt).readlines end def parse_data(email, line, header) tokens = tokenize(line) hash = {} header.each_with_index do |column, index| next if column.blank? value = tokens[index] next if value&.include?(email) hash[column] = value end hash end private def tokenize(line) CSV.parse_line(line).map do |token| token&.strip end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems