class ArticleJSON::Import::GoogleDoc::HTML::TextBoxParser
Public Class Methods
new(type_node: ,nodes:, css_analyzer:)
click to toggle source
@param [Nokogiri::HTML::Node] type_node Document node that states
that this is a textbox. May contain tags, too.
@param [Array] nodes @param [ArticleJSON::Import::GoogleDoc::HTML::CSSAnalyzer] css_analyzer
# 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
Public Instance Methods
content()
click to toggle source
Parse the text box's nodes to get a list of sub elements Supported sub elements are: headings, paragraphs & lists. @return [Array]
# 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()
click to toggle source
Hash representation of this text box @return [ArticleJSON::Elements::TextBox]
# 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
Private Instance Methods
parse_sub_node(node)
click to toggle source
# File lib/article_json/import/google_doc/html/text_box_parser.rb, line 50 def parse_sub_node(node) case NodeAnalyzer.new(node).type when :heading HeadingParser.new(node: node).element when :paragraph ParagraphParser .new(node: node, css_analyzer: @css_analyzer) .element when :list ListParser.new(node: node, css_analyzer: @css_analyzer).element end end