Sha256: 45431977c37010c8b3b232c705ce9402a87b33b7b7ba55aa1f8e12b52e5ad208

Contents?: true

Size: 755 Bytes

Versions: 4

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

require 'cased/sensitive/range'

module Cased
  module Sensitive
    class String < String
      attr_reader :label, :string

      def initialize(string, label: nil)
        super(string)
        @label = label
      end

      def range(key:)
        Cased::Sensitive::Range.new(
          label: label,
          key: key,
          begin_offset: 0,
          end_offset: length,
        )
      end

      def matches(regex)
        offset = 0
        matches = []

        while (result = match(regex, offset))
          matches.push(result)
          offset = result.end(0)
        end

        matches
      end

      def ==(other)
        super(other) &&
          @label == other.label
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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