Class: GovukTechDocs::UniqueIdentifierGenerator
- Inherits:
-
Object
- Object
- GovukTechDocs::UniqueIdentifierGenerator
- Includes:
- Singleton
- Defined in:
- lib/govuk_tech_docs/unique_identifier_generator.rb
Defined Under Namespace
Classes: Anchor
Instance Attribute Summary collapse
-
#anchors ⇒ Object
readonly
Returns the value of attribute anchors.
Instance Method Summary collapse
- #create(id, level) ⇒ Object
-
#initialize ⇒ UniqueIdentifierGenerator
constructor
A new instance of UniqueIdentifierGenerator.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ UniqueIdentifierGenerator
Returns a new instance of UniqueIdentifierGenerator.
11 12 13 |
# File 'lib/govuk_tech_docs/unique_identifier_generator.rb', line 11 def initialize reset end |
Instance Attribute Details
#anchors ⇒ Object (readonly)
Returns the value of attribute anchors.
9 10 11 |
# File 'lib/govuk_tech_docs/unique_identifier_generator.rb', line 9 def anchors @anchors end |
Instance Method Details
#create(id, level) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/govuk_tech_docs/unique_identifier_generator.rb', line 15 def create(id, level) anchor = heading_slug(id) unless unique?(anchor) anchor = prefixed_by_parent(anchor, level) end unless unique?(anchor) anchor = suffixed_with_number(anchor) end @anchors << Anchor.new(anchor, level) anchor end |
#reset ⇒ Object
31 32 33 |
# File 'lib/govuk_tech_docs/unique_identifier_generator.rb', line 31 def reset @anchors = [] end |