Class: NotionRubyMapping::MentionObject

Inherits:
RichTextObject show all
Defined in:
lib/notion_ruby_mapping/objects/mention_object.rb

Overview

TextObject

Instance Attribute Summary

Attributes inherited from RichTextObject

#options, #will_update

Instance Method Summary collapse

Methods inherited from RichTextObject

#bold=, #clear_will_update, #code=, #color=, create_from_json, #href=, #italic=, #plain_text=, #property_values_json, #strikethrough=, text_object, #underline=

Constructor Details

#initialize(options = {}) ⇒ MentionObject



7
8
9
10
11
12
13
# File 'lib/notion_ruby_mapping/objects/mention_object.rb', line 7

def initialize(options = {})
  super "mention", options
  return unless (url = options["link_preview"])

  @options["href"] = url
  @options["plain_text"] = url
end

Instance Method Details

#page_idString, NilClass

Returns:

  • (String, NilClass)


16
17
18
# File 'lib/notion_ruby_mapping/objects/mention_object.rb', line 16

def page_id
  @options["page_id"]
end

#partial_property_values_jsonObject



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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/notion_ruby_mapping/objects/mention_object.rb', line 25

def partial_property_values_json
  if @options.key? "user_id"
    {
      "type" => "user",
      "user" => {
        "object" => "user",
        "id" => @options["user_id"],
      },
    }
  elsif @options.key? "page_id"
    {
      "type" => "page",
      "page" => {
        "id" => @options["page_id"],
      },
    }
  elsif @options.key? "database_id"
    {
      "type" => "database",
      "database" => {
        "id" => @options["database_id"],
      },
    }
  elsif @options.key? "start"
    {
      "type" => "date",
      "date" => @options.slice("start", "end", "time_zone"),
    }
  elsif @options.key? "template_mention"
    sub = case @options["template_mention"]
          when "today"
            @options["plain_text"] = "@Today"
            {
              "type" => "template_mention_date",
              "template_mention_date" => "today",
            }
          when "now"
            @options["plain_text"] = "@Now"
            {
              "type" => "template_mention_date",
              "template_mention_date" => "now",
            }
          else
            @options["plain_text"] = "@Me"
            {
              "type" => "template_mention_user",
              "template_mention_user" => "me",
            }
          end
    {
      "type" => "template_mention",
      "template_mention" => sub,
    }
  elsif @options.key? "link_preview"
    {
      "type" => "link_preview",
      "link_preview" => {
        "url" => @options["link_preview"],
      },
    }
  elsif @options.key? "href"
    {
      "type" => "link_mention",
      "link_mention" => @options.slice("href", "icon_url", "link_provider", "thumbnail_url", "title"),
    }
  else
    raise StandardError, "Irregular mention type: #{@options.keys}"
  end
end

#textString (frozen)

Returns:

  • (String (frozen))


21
22
23
# File 'lib/notion_ruby_mapping/objects/mention_object.rb', line 21

def text
  ""
end