Class: DMARC::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/dmarc/parser.rb

Overview

DMARC parser.

Defined Under Namespace

Classes: Transform

Class Method Summary collapse

Class Method Details

.parse(record) ⇒ Hash{Symbol => Object}

Parses a DMARC record.

Parameters:

  • record (String)

    The raw DMARC record to parse.

Returns:

  • (Hash{Symbol => Object})

    The Hash of tags within the record.



216
217
218
219
220
221
222
223
# File 'lib/dmarc/parser.rb', line 216

def self.parse(record)
  tags = Transform.new.apply(new.parse(record))
  hash = {}

  tags.each { |tag| hash.merge!(tag) }

  return hash
end

.tag_rule(name, tag, &block) ⇒ Object



45
46
47
48
49
50
# File 'lib/dmarc/parser.rb', line 45

def self.tag_rule(name,tag,&block)
  rule(:"dmarc_#{name}") do
    str(tag) >> wsp? >> str('=') >> wsp? >>
    (instance_eval(&block).as(tag.to_sym) | unknown_value)
  end
end