scribe/src/classes/page_converter.cr

21 lines
671 B
Crystal
Raw Normal View History

class PageConverter
def convert(data : PostResponse::Data) : Page
title, content = title_and_content(data)
author = data.post.creator
2021-09-04 23:32:27 +02:00
created_at = Time.unix_ms(data.post.createdAt)
Page.new(
title: title,
author: author,
2021-09-04 23:32:27 +02:00
created_at: Time.unix_ms(data.post.createdAt),
nodes: ParagraphConverter.new.convert(content)
)
end
def title_and_content(data : PostResponse::Data) : {String, Array(PostResponse::Paragraph)}
title = data.post.title
paragraphs = data.post.content.bodyModel.paragraphs
non_content_paragraphs = paragraphs.reject { |para| para.text == title }
{title, non_content_paragraphs}
end
end