Sha256: 76453f479c34374f5a987cfc91c7164b2a7da49df01f6802a780c5421085306f

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Cased
  module Sensitive
    class Range
      # Public: The human label describing what sensitive information was
      # label. Username, email, date of birth, etc.
      attr_reader :label

      # Public: The JSON key.
      attr_reader :key

      # Public: This is the identifier that groups sensitive ranges together.
      # This could be an identifier to an individual for example.
      attr_reader :identifier

      # Public: The beginning offset of the sensitive value in the original value.
      attr_reader :begin_offset

      # Public: The end offset of the sensitive value in the original value.
      attr_reader :end_offset

      def initialize(key:, begin_offset:, end_offset:, label: nil, identifier: nil)
        raise ArgumentError, 'missing key' if key.nil?
        raise ArgumentError, 'missing begin_offset' if begin_offset.nil?
        raise ArgumentError, 'missing end_offset' if end_offset.nil?

        @label = label
        @key = key
        @identifier = identifier
        @begin_offset = begin_offset
        @end_offset = end_offset
      end

      def ==(other)
        @begin_offset == other.begin_offset &&
          @end_offset == other.end_offset &&
          @label == other.label &&
          @key == other.key &&
          @identifier == other.identifier
      end

      def to_h
        {
          begin: @begin_offset,
          end: @end_offset,
        }.tap do |hash|
          hash[:label] = label if label
          hash[:identifier] = identifier if identifier
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cased-ruby-0.8.0 lib/cased/sensitive/range.rb
cased-ruby-0.7.1 lib/cased/sensitive/range.rb
cased-ruby-0.7.0 lib/cased/sensitive/range.rb
cased-ruby-0.6.1 lib/cased/sensitive/range.rb