Class: Decidim::DirectVerifications::Parsers::BaseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/direct_verifications/parsers/base_parser.rb

Overview

Abstract class all concrete parsers should inherit from. They are expected to implement #header, #lines, and #parse_data methods.

Direct Known Subclasses

MetadataParser, NameParser

Constant Summary collapse

EMAIL_REGEXP =
/([A-Z0-9+._-]+@[A-Z0-9._-]+\.[A-Z0-9_-]+)\b/i.freeze

Instance Method Summary collapse

Constructor Details

#initialize(txt) ⇒ BaseParser

Returns a new instance of BaseParser.



11
12
13
14
# File 'lib/decidim/direct_verifications/parsers/base_parser.rb', line 11

def initialize(txt)
  @txt = txt
  @emails = {}
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/decidim/direct_verifications/parsers/base_parser.rb', line 16

def to_h
  lines.each do |line|
    EMAIL_REGEXP.match(line) do |match|
      email = normalize(match[0])
      emails[email] = parse_data(email, line, header)
    end
  end

  emails
end