Class: ArticleJSON::Import::GoogleDoc::HTML::TextBoxParser

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

Instance Method Summary collapse

Methods included from Shared::Float

#float

Constructor Details

#initialize(nodes:, css_analyzer:) ⇒ TextBoxParser



10
11
12
13
14
15
16
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 10

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

  # First node of the text box indicates floating behavior
  @float_node = @nodes.first
end

Instance Method Details

#contentArray

Parse the text box’s nodes to get a list of sub elements Supported sub elements are: headings, paragraphs & lists.



21
22
23
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 21

def content
  @nodes.map { |node| parse_sub_node(node) }.compact
end

#elementArticleJSON::Elements::TextBox

Hash representation of this text box



27
28
29
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 27

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