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(type_node:, nodes:, css_analyzer:) ⇒ TextBoxParser

Returns a new instance of TextBoxParser.

Parameters:



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

def initialize(type_node: ,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
  @type_node = type_node
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.

Returns:

  • (Array)


25
26
27
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 25

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

#elementArticleJSON::Elements::TextBox

Hash representation of this text box



40
41
42
43
44
45
46
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 40

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

#tagsArray[Symbol]

Extract any potential tags, specified in brackets after the Textbox definition

Returns:

  • (Array[Symbol])


31
32
33
34
35
36
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 31

def tags
  match = /(.*?)[\s\u00A0]+\[(?<tags>.*)\]/
            .match(@type_node.inner_text)
  return [] unless match
  match[:tags].split(' ')
end