Class: Decidim::DirectVerifications::Parsers::BaseParser
- Inherits:
-
Object
- Object
- Decidim::DirectVerifications::Parsers::BaseParser
- 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
Constant Summary collapse
- EMAIL_REGEXP =
/([A-Z0-9+._-]+@[A-Z0-9._-]+\.[A-Z0-9_-]+)\b/i.freeze
Instance Method Summary collapse
-
#initialize(txt) ⇒ BaseParser
constructor
A new instance of BaseParser.
- #to_h ⇒ Object
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_h ⇒ Object
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 |