Class: GovukTechDocs::TableOfContents::Heading
- Inherits:
- 
      Object
      
        - Object
- GovukTechDocs::TableOfContents::Heading
 
- Defined in:
- lib/govuk_tech_docs/table_of_contents/heading.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #href ⇒ Object
- 
  
    
      #initialize(element_name:, text:, attributes:, page_url: "")  ⇒ Heading 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Heading. 
- #size ⇒ Object
- #title ⇒ Object
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
| 27 28 29 30 31 | # File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 27 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
| 15 16 17 18 19 20 21 | # File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 15 def href if @page_url != "" && size == 1 @page_url else "#{@page_url}##{@attributes['id']}" end end | 
#size ⇒ Object
| 11 12 13 | # File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 11 def size @element_name.scan(/h(\d)/) && ::Regexp.last_match(1) && Integer(::Regexp.last_match(1)) end | 
#title ⇒ Object
| 23 24 25 | # File 'lib/govuk_tech_docs/table_of_contents/heading.rb', line 23 def title @text end |