Class: ArticleJSON::Import::GoogleDoc::HTML::TextBoxParser
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::TextBoxParser
- Includes:
- Shared::Float
- Defined in:
- lib/article_json/import/google_doc/html/text_box_parser.rb
Instance Method Summary collapse
-
#content ⇒ Array
Parse the text box’s nodes to get a list of sub elements Supported sub elements are: headings, paragraphs & lists.
-
#element ⇒ ArticleJSON::Elements::TextBox
Hash representation of this text box.
-
#initialize(type_node:, nodes:, css_analyzer:) ⇒ TextBoxParser
constructor
A new instance of TextBoxParser.
-
#tags ⇒ Array[Symbol]
Extract any potential tags, specified in brackets after the Textbox definition.
Methods included from Shared::Float
Constructor Details
#initialize(type_node:, nodes:, css_analyzer:) ⇒ TextBoxParser
Returns a new instance of TextBoxParser.
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
#content ⇒ Array
Parse the text box’s nodes to get a list of sub elements Supported sub elements are: headings, paragraphs & lists.
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 |
#element ⇒ ArticleJSON::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: ) end |
#tags ⇒ Array[Symbol]
Extract any potential tags, specified in brackets after the Textbox definition
31 32 33 34 35 36 |
# File 'lib/article_json/import/google_doc/html/text_box_parser.rb', line 31 def match = /(.*?)[\s\u00A0]+\[(?<tags>.*)\]/ .match(@type_node.inner_text) return [] unless match match[:tags].split(' ') end |