class ArticleJSON::Export::PlainText::Elements::List
Public Instance Methods
export()
click to toggle source
List
of strings, one per line. If the list type is “ordered” then each line is preceded with a number, otherwise a dash. Newlines within a list item are indented accordingly. @return [String]
# File lib/article_json/export/plain_text/elements/list.rb, line 10 def export "#{list}\n" end
Private Instance Methods
list()
click to toggle source
Plain-text list of items using the right prefix @return [String]
# File lib/article_json/export/plain_text/elements/list.rb, line 18 def list @element .content &.each_with_index &.map do |content, index| "#{prefix(index)} #{paragraph_exporter.new(content).export}" .gsub(/\n(?!$)/, newline_with_indention) end&.join || '' end
newline_with_indention()
click to toggle source
Newline followed by the right amount of spaces to align with the indentation from the prefix @return [String]
# File lib/article_json/export/plain_text/elements/list.rb, line 37 def newline_with_indention "\n " + ' ' * prefix(0).length end
paragraph_exporter()
click to toggle source
Get the exporter class for paragraph elements @return [ArticleJSON::Export::Common::HTML::Elements::Base]
# File lib/article_json/export/plain_text/elements/list.rb, line 43 def paragraph_exporter self.class.exporter_by_type(:paragraph) end
prefix(index)
click to toggle source
Prefix used for every list item @param [String] index
# File lib/article_json/export/plain_text/elements/list.rb, line 30 def prefix(index) @element.list_type == :ordered ? "#{index + 1}." : '-' end