Class: ArticleJSON::Import::GoogleDoc::HTML::HeadingParser

Inherits:
Object
  • Object
show all
Defined in:
lib/article_json/import/google_doc/html/heading_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(node:) ⇒ HeadingParser

Returns a new instance of HeadingParser.

Parameters:

  • node (Nokogiri::HTML::Node)


7
8
9
# File 'lib/article_json/import/google_doc/html/heading_parser.rb', line 7

def initialize(node:)
  @node = node
end

Instance Method Details

#contentString

The raw text content of the heading, without any markup

Returns:

  • (String)


13
14
15
# File 'lib/article_json/import/google_doc/html/heading_parser.rb', line 13

def content
  @node.inner_text
end

#elementArticleJSON::Elements::Heading



31
32
33
# File 'lib/article_json/import/google_doc/html/heading_parser.rb', line 31

def element
  ArticleJSON::Elements::Heading.new(level: level, content: content)
end

#levelInteger

Determine the level of the heading The level corresponds to the header tag, e.g. ‘<h3>` is level 3.

Returns:

  • (Integer)


20
21
22
23
24
25
26
27
28
# File 'lib/article_json/import/google_doc/html/heading_parser.rb', line 20

def level
  case @node.name
    when 'h1' then 1
    when 'h2' then 2
    when 'h3' then 3
    when 'h4' then 4
    when 'h5' then 5
  end
end