Class: ArticleJSON::Import::GoogleDoc::HTML::ListParser

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

Instance Method Summary collapse

Constructor Details

#initialize(node:, css_analyzer:) ⇒ ListParser

Returns a new instance of ListParser.

Parameters:



8
9
10
11
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 8

def initialize(node:, css_analyzer:)
  @node = node
  @css_analyzer = css_analyzer
end

Instance Method Details

#contentArray[ArticleJSON::Elements::Paragraph]

Parse the list’s sub nodes to get a set of paragraphs



24
25
26
27
28
29
30
31
32
33
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 24

def content
  @node
    .children
    .select { |node| node.name == 'li' }
    .map do |node|
      ParagraphParser
        .new(node: node, css_analyzer: @css_analyzer)
        .element
    end
end

#elementArticleJSON::Elements::List



36
37
38
39
40
41
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 36

def element
  ArticleJSON::Elements::List.new(
    list_type: list_type,
    content: content
  )
end

#list_typeSymbol

Determine the list type, either ordered or unordered

Returns:

  • (Symbol)


15
16
17
18
19
20
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 15

def list_type
  case @node.name
    when 'ol' then :ordered
    when 'ul' then :unordered
  end
end