Class: DMARC::Parser

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

Defined Under Namespace

Classes: Transform

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



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

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

Instance 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.



189
190
191
192
193
194
195
196
# File 'lib/dmarc/parser.rb', line 189

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

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

  return hash
end