Class: ArticleJSON::Import::GoogleDoc::HTML::HeadingParser
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::HeadingParser
- Defined in:
- lib/article_json/import/google_doc/html/heading_parser.rb
Instance Method Summary collapse
-
#content ⇒ String
The raw text content of the heading, without any markup.
- #element ⇒ ArticleJSON::Elements::Heading
-
#initialize(node:) ⇒ HeadingParser
constructor
A new instance of HeadingParser.
-
#level ⇒ Integer
Determine the level of the heading The level corresponds to the header tag, e.g.
Constructor Details
#initialize(node:) ⇒ HeadingParser
Returns a new instance of HeadingParser.
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
#content ⇒ String
The raw text content of the heading, without any markup
13 14 15 |
# File 'lib/article_json/import/google_doc/html/heading_parser.rb', line 13 def content @node.inner_text end |
#element ⇒ ArticleJSON::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 |
#level ⇒ Integer
Determine the level of the heading The level corresponds to the header tag, e.g. ‘<h3>` is level 3.
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 |