19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 19
def self.create_from_json(json)
type = json["type"]
options = (json["annotations"] || {}).merge(json.slice("plain_text", "href"))
case type
when "text"
TextObject.new json["plain_text"], options
when "equation"
EquationObject.new json["equation"]["expression"], options
when "mention"
mention = json["mention"]
case mention["type"]
when "user"
MentionObject.new options.merge({"user_id" => mention["user"]["id"]})
when "page"
MentionObject.new options.merge({"page_id" => mention["page"]["id"]})
when "database"
MentionObject.new options.merge({"database_id" => mention["database"]["id"]})
when "date"
MentionObject.new options.merge(mention["date"].slice("start", "end", "time_zone"))
when "template_mention"
template_mention = mention["template_mention"]
case template_mention["type"]
when "template_mention_date"
MentionObject.new options.merge({"template_mention" => template_mention["template_mention_date"]})
else
MentionObject.new options.merge({"template_mention" => template_mention["template_mention_user"]})
end
when "link_preview"
MentionObject.new options.merge({"link_preview" => mention["link_preview"]["url"]})
else
raise StandardError, "Unknown mention type: #{mention["type"]}"
end
else
raise StandardError, json
end
end
|