Class: ArticleJSON::Import::GoogleDoc::HTML::QuoteParser

Inherits:
Object
  • Object
show all
Includes:
Shared::Caption, Shared::Float
Defined in:
lib/article_json/import/google_doc/html/quote_parser.rb

Instance Method Summary collapse

Methods included from Shared::Float

#float

Methods included from Shared::Caption

#caption

Constructor Details

#initialize(nodes:, css_analyzer:) ⇒ QuoteParser

Returns a new instance of QuoteParser.

Parameters:



11
12
13
14
15
16
17
18
19
# File 'lib/article_json/import/google_doc/html/quote_parser.rb', line 11

def initialize(nodes:, css_analyzer:)
  @nodes = nodes.reject { |node| NodeAnalyzer.new(node).empty? }
  @css_analyzer = css_analyzer

  # First node of the quote indicates floating behavior
  @float_node = @nodes.first
  # Last node of the quote contains the caption
  @caption_node = @nodes.last
end

Instance Method Details

#contentArray[ArticleJSON::Elements::Paragraph]

Parse the quote’s nodes to get a set of paragraphs The last node is ignored as it contains the quote caption



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

def content
  @nodes
    .take(@nodes.size - 1)
    .map do |node|
      ParagraphParser
        .new(node: node, css_analyzer: @css_analyzer)
        .element
    end
end

#elementArticleJSON::Elements::Quote



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

def element
  ArticleJSON::Elements::Quote.new(
    content: content,
    caption: caption,
    float: float
  )
end