2021-08-14 23:36:10 +02:00
|
|
|
class PageConverter
|
2021-09-04 23:15:30 +02:00
|
|
|
def convert(data : PostResponse::Data) : Page
|
2021-10-04 00:14:46 +02:00
|
|
|
title, content = title_and_content(data)
|
2021-09-15 21:44:28 +02:00
|
|
|
author = data.post.creator
|
2021-09-04 23:32:27 +02:00
|
|
|
created_at = Time.unix_ms(data.post.createdAt)
|
2021-09-04 23:15:30 +02:00
|
|
|
Page.new(
|
2021-10-04 00:14:46 +02:00
|
|
|
title: title,
|
2021-09-04 23:15:30 +02:00
|
|
|
author: author,
|
2021-09-04 23:32:27 +02:00
|
|
|
created_at: Time.unix_ms(data.post.createdAt),
|
2021-09-04 23:15:30 +02:00
|
|
|
nodes: ParagraphConverter.new.convert(content)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-10-04 00:14:46 +02:00
|
|
|
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}
|
2021-08-14 23:36:10 +02:00
|
|
|
end
|
|
|
|
end
|