<commit_before>require 'dkim/query/exceptions'
require 'dkim/query/parser'
require 'dkim/query/malformed_key'

module DKIM
  module Query
    class Key

      attr_reader :v
      alias version v

      attr_reader :g
      alias granularity g

      attr_reader :h
      alias hash h

      attr_reader :k
      alias key k

      attr_reader :n
      alias notes n

      attr_reader :p
      alias public_key p

      attr_reader :s
      alias service_type s

      attr_reader :t
      alias flags t

      #
      # Initialize the key.
      #
      # @param [Hash{Symbol => Symbol,String}] tags
      #   Tags for the key.
      #
      # @option tags [Symbol] :v
      #
      # @option tags [Symbol] :g
      #
      # @option tags [Symbol] :h
      #
      # @option tags [Symbol] :k
      #
      # @option tags [Symbol] :n
      #
      # @option tags [Symbol] :p
      #
      # @option tags [Symbol] :s
      #
      # @option tags [Symbol] :t
      #
      def initialize(tags={})
        @v, @g, @h, @k, @n, @p, @s, @t = tags.values_at(:v,:g,:h,:k,:n,:p,:s,:t)
      end

      #
      # Parses a DKIM Key record.
      #
      # @param [String] record
      #   The DKIM key record.
      #
      # @return [Key]
      #   The new key.
      #
      # @raise [Parslet::ParseFailed]
      #   Could not parse the DKIM Key record.
      #
      def self.parse!(record)
        new(Parser.parse(record))
      rescue Parslet::ParseFailed => error
        raise(InvalidKey.new(error.message,error.cause))
      end

      #
      # Parses a DKIM Key record.
      #
      # @param [String] record
      #   The DKIM key record.
      #
      # @return [Key, MalformedKey]
      #   The parsed key. If the key could not be parsed, a {MalformedKey}
      #   will be returned.
      #
      def self.parse(record)
        begin
          parse!(record)
        rescue Parslet::ParseFailed => error
          MalformedKey.new(record,error.cause)<commit_msg>Updated the @raise tag for Key.parse!.<commit_after>require 'dkim/query/exceptions'
require 'dkim/query/parser'
require 'dkim/query/malformed_key'

module DKIM
  module Query
    class Key

      attr_reader :v
      alias version v

      attr_reader :g
      alias granularity g

      attr_reader :h
      alias hash h

      attr_reader :k
      alias key k

      attr_reader :n
      alias notes n

      attr_reader :p
      alias public_key p

      attr_reader :s
      alias service_type s

      attr_reader :t
      alias flags t

      #
      # Initialize the key.
      #
      # @param [Hash{Symbol => Symbol,String}] tags
      #   Tags for the key.
      #
      # @option tags [Symbol] :v
      #
      # @option tags [Symbol] :g
      #
      # @option tags [Symbol] :h
      #
      # @option tags [Symbol] :k
      #
      # @option tags [Symbol] :n
      #
      # @option tags [Symbol] :p
      #
      # @option tags [Symbol] :s
      #
      # @option tags [Symbol] :t
      #
      def initialize(tags={})
        @v, @g, @h, @k, @n, @p, @s, @t = tags.values_at(:v,:g,:h,:k,:n,:p,:s,:t)
      end

      #
      # Parses a DKIM Key record.
      #
      # @param [String] record
      #   The DKIM key record.
      #
      # @return [Key]
      #   The new key.
      #
      # @raise [InvalidKey]
      #   Could not parse the DKIM Key record.
      #
      def self.parse!(record)
        new(Parser.parse(record))
      rescue Parslet::ParseFailed => error
        raise(InvalidKey.new(error.message,error.cause))
      end

      #
      # Parses a DKIM Key record.
      #
      # @param [String] record
      #   The DKIM key record.
      #
      # @return [Key, MalformedKey]
      #   The parsed key. If the key could not be parsed, a {MalformedKey}
      #   will be returned.
      #
      def self.parse(record)
        begin
          parse!(record)
        rescue Parslet::ParseFailed => error
          MalformedKey.new(record,error.cause)
{'fraction_non_alphanumeric': 0.10838186882755128, 'fraction_numerical': 0.0, 'mean_word_length': 1.65814266487214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7352336', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1289, 'n_words': 362}