Sha256: af5ca3cedfba3829a9772fa622c2a569187891a58de14fb8af7a900d02a438f2

Contents?: true

Size: 652 Bytes

Versions: 5

Compression:

Stored size: 652 Bytes

Contents

module GovukTechDocs
  module TableOfContents
    class Heading
      def initialize(element_name:, text:, attributes:)
        @element_name = element_name
        @text = text
        @attributes = attributes
      end

      def size
        @element_name.scan(/h(\d)/) && $1 && Integer($1)
      end

      def href
        '#' + @attributes['id']
      end

      def title
        @text
      end

      def ==(other)
        @element_name == other.instance_variable_get("@element_name") &&
          @text == other.instance_variable_get("@text") &&
          @attributes == other.instance_variable_get("@attributes")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
govuk_tech_docs-1.3.1 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-1.3.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-1.2.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-1.1.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-1.0.0 lib/govuk_tech_docs/table_of_contents/heading.rb