Class: GovukTechDocs::TableOfContents::Heading

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_tech_docs/table_of_contents/heading.rb

Instance Method Summary collapse

Constructor Details

#initialize(element_name:, text:, attributes:) ⇒ Heading

Returns a new instance of Heading.



4
5
6
7
8
# File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 4

def initialize(element_name:, text:, attributes:)
  @element_name = element_name
  @text = text
  @attributes = attributes
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
# File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 22

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

#href ⇒ Object



14
15
16
# File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 14

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

#size ⇒ Object



10
11
12
# File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 10

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

#title ⇒ Object



18
19
20
# File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 18

def title
  @text
end