Class: TopSecret::Text::LabelSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/top_secret/text/label_sequence.rb

Overview

Generates unique, sequenced label symbols for each label type.

Examples:

sequence = TopSecret::Text::LabelSequence.new
sequence.next_label("EMAIL")       # => :EMAIL_1
sequence.next_label("EMAIL")       # => :EMAIL_2
sequence.next_label("PERSON")      # => :PERSON_1

Instance Method Summary collapse

Constructor Details

#initializeLabelSequence

Creates a new LabelSequence instance with all counters at zero.



14
15
16
# File 'lib/top_secret/text/label_sequence.rb', line 14

def initialize
  @counters = Hash.new(0)
end

Instance Method Details

#next_label(label_type) ⇒ Symbol

Returns the next sequenced label for the given label type.

Parameters:

  • label_type (String)

    the label type (e.g., “EMAIL”, “CREDIT_CARD”)

Returns:

  • (Symbol)

    the sequenced label (e.g., :EMAIL_1, :EMAIL_2)



22
23
24
25
# File 'lib/top_secret/text/label_sequence.rb', line 22

def next_label(label_type)
  @counters[label_type] += 1
  :"#{label_type}#{TopSecret::LABEL_DELIMITER}#{@counters[label_type]}"
end