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.



201
202
203
204
205
206
207
208
# File 'lib/dmarc/parser.rb', line 201

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



43
44
45
46
47
48
# File 'lib/dmarc/parser.rb', line 43

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