Class: Cased::Sensitive::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/cased/sensitive/range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, begin_offset:, end_offset:, label: nil, identifier: nil) ⇒ Range

Returns a new instance of Range.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cased/sensitive/range.rb', line 23

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

Instance Attribute Details

#begin_offsetObject (readonly)

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



18
19
20
# File 'lib/cased/sensitive/range.rb', line 18

def begin_offset
  @begin_offset
end

#end_offsetObject (readonly)

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



21
22
23
# File 'lib/cased/sensitive/range.rb', line 21

def end_offset
  @end_offset
end

#identifierObject (readonly)

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



15
16
17
# File 'lib/cased/sensitive/range.rb', line 15

def identifier
  @identifier
end

#keyObject (readonly)

Public: The JSON key.



11
12
13
# File 'lib/cased/sensitive/range.rb', line 11

def key
  @key
end

#labelObject (readonly)

Public: The human label describing what sensitive information was label. Username, email, date of birth, etc.



8
9
10
# File 'lib/cased/sensitive/range.rb', line 8

def label
  @label
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/cased/sensitive/range.rb', line 35

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

#to_hObject



43
44
45
46
47
48
49
50
51
# File 'lib/cased/sensitive/range.rb', line 43

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