Class: ArticleJSON::Import::GoogleDoc::HTML::ListParser
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::ListParser
- Defined in:
- lib/article_json/import/google_doc/html/list_parser.rb
Instance Method Summary collapse
-
#content ⇒ Array[ArticleJSON::Elements::Paragraph]
Parse the list’s sub nodes to get a set of paragraphs.
- #element ⇒ ArticleJSON::Elements::List
-
#initialize(node:, css_analyzer:) ⇒ ListParser
constructor
A new instance of ListParser.
-
#list_type ⇒ Symbol
Determine the list type, either ordered or unordered.
Constructor Details
#initialize(node:, css_analyzer:) ⇒ ListParser
Returns a new instance of ListParser.
8 9 10 11 |
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 8 def initialize(node:, css_analyzer:) @node = node @css_analyzer = css_analyzer end |
Instance Method Details
#content ⇒ Array[ArticleJSON::Elements::Paragraph]
Parse the list’s sub nodes to get a set of paragraphs
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 24 def content @node .children .select { |node| node.name == 'li' } .map do |node| ParagraphParser .new(node: node, css_analyzer: @css_analyzer) .element end end |
#element ⇒ ArticleJSON::Elements::List
36 37 38 39 40 41 |
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 36 def element ArticleJSON::Elements::List.new( list_type: list_type, content: content ) end |
#list_type ⇒ Symbol
Determine the list type, either ordered or unordered
15 16 17 18 19 20 |
# File 'lib/article_json/import/google_doc/html/list_parser.rb', line 15 def list_type case @node.name when 'ol' then :ordered when 'ul' then :unordered end end |