๐ŸŽ›๏ธ

RichTextArray

Some properties and Database title have an array of RichTextObject. RichTextArray is the delegate class for the array of RichTextObject. Moreover, some methods of TitleProperty, RichTextProperty and Database.title delegate to the included RichTextArray.

1. Singleton methods

rich_text_array(key, text_info = [])

  • [PARAM] key keyword for JSON
  • [PARAM(optional)] text_info
    • ๐Ÿ“ƒ
      The following objects are used for this argument.
      • a String like as โ€œtextโ€ (String)
      • an Array of Strings (Array of Strings)
      • a RichTextObject (RichTextObject)
      • an Array of RichTextObjects (Array of RichTextObjects)
      • a RichTextArray (RichTextArray)
RichTextArray can be created by a String, some Strings, a RichTextObject and some RichTextObjects. RichTextArray has Array of RichTextObjects. String values will convert to simple TextObjects. If string_contes is already RichTextArray, this method returns the given the RichTextArray.
nullString = RichTextArray.rich_text_array "title" aString = RichTextArray.rich_text_array "title", "A string" twoStrings = RichTextArray.rich_text_array "title", %W[ABC\\n DEF] aTextObject = RichTextArray.rich_text_array "title", TextObject.new("A TextObject") textMentionObjects = RichTextArray.rich_text_array "title", [TextObject.new("A TextObject"), MentionObject.new(user_id: "ABC")] richTextArray = RichTextArray.rich_text_array "title", textMentionObjects # richTextArray == textMentionObjects

2. Instance methods

<<(value) โ†’ RichTextObject

  • [PARAM] value
    • a String like as โ€œtextโ€ (String)
    • a RichTextObject (RichTextObject)
<< appends a text or RichTextObject. String value will convert to simple TextObject.
db.database_title << "title" db.database_title << MentionObject.new(user_id: "AAA")

self[pos] โ†’ RichTextObject

  • [PARAM] pos index
self[pos] returns a RichTextObject.

delete_at(pos) โ†’ RichTextObject

  • [PARAM] pos
    • index of object that you want to delete
delete_at obtain the object specified by the index and delete from the array.
db.database_title.delete_at 0 # => #<NotionRubyMapping::TextObject:...>

each { |item| ... } โ†’ self each โ†’ Enumerator

RichTextArray is an Enumerable object, so usually combines with .each method.
db.database_title.each do |rto| # exec some methods for a RichTextObject end

full_text

full_text generates a joined plain text.
db.database_title.full_text => "New database title(Added)"

rich_text_objects=(text_info)

  • [PARAM(optional)] text_info
    • ๐Ÿ“ƒ
      The following objects are used for this argument.
      • a String like as โ€œtextโ€ (String)
      • an Array of Strings (Array of Strings)
      • a RichTextObject (RichTextObject)
      • an Array of RichTextObjects (Array of RichTextObjects)
      • a RichTextArray (RichTextArray)
Rich text objects in RichTextArray can be replaced by a String, some Strings, a RichTextObject and some RichTextObjects. RichTextArray has Array of RichTextObjects. String values will convert to simple TextObjects. If string_contents is already RichTextArray, the rich text objects are copyed from the given RichTextArray.
rta = RichTextArray "title" rta.rich_text_objects = "A string"; rta.full_text # => "ABC" rta.rich_text_objects = %W[ABC\\n DEF]; rta.full_text # => "ABC\\nDEF" rta.rich_text_objects = TextObject.new("A TextObject"); rta.full_text # => "A TextObject" rta.rich_text_objects = [TextObject.new("A TextObject"), MentionObject.new(user_id: "ABC")]; rta.full_text # => "A TextObject" rta.rich_text_objects = RichTextArray.rich_text_array("title", "ABC"); rta.full_text # => "ABC"