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:, page_url: '') ⇒ Heading

Returns a new instance of Heading.



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#hrefObject



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

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

#sizeObject



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

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

#titleObject



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

def title
  @text
end