Class: Cased::Sensitive::String

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, label: nil) ⇒ String

Returns a new instance of String.



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

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

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
39
# File 'lib/cased/sensitive/string.rb', line 36

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

#matches(regex) ⇒ Object



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

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

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

  matches
end

#range(key:) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/cased/sensitive/string.rb', line 15

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