Sha256: 73108cb6d99524d33245184d85b2834ebcd77649b5aa7fc7515f4235863da0f3

Contents?: true

Size: 794 Bytes

Versions: 11

Compression:

Stored size: 794 Bytes

Contents

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

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

      def href
        if @page_url != "" && size == 1
          @page_url
        else
          @page_url + "#" + @attributes["id"]
        end
      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

11 entries across 11 versions & 1 rubygems

Version Path
govuk_tech_docs-3.3.1 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.3.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.2.1 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.2.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.1.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.0.1 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-3.0.0 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-2.4.3 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-2.4.2 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-2.4.1 lib/govuk_tech_docs/table_of_contents/heading.rb
govuk_tech_docs-2.4.0 lib/govuk_tech_docs/table_of_contents/heading.rb