Class: NotionRubyMapping::RichTextObject
- Inherits:
-
Object
- Object
- NotionRubyMapping::RichTextObject
- Defined in:
- lib/notion_ruby_mapping/objects/rich_text_object.rb
Overview
RichTextObject
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#will_update ⇒ Object
readonly
Returns the value of attribute will_update.
Class Method Summary collapse
- .create_from_json(json) ⇒ Object
-
.text_object(to) ⇒ NotionRubyMapping::RichTextObject
RichTextObject.
Instance Method Summary collapse
-
#bold=(flag) ⇒ Boolean
Input flag.
-
#code=(flag) ⇒ Boolean
Input flag.
-
#color=(color) ⇒ String
Input color.
-
#href=(url) ⇒ String
Input text.
- #initialize(type, options = {}) ⇒ TextObject constructor
-
#italic=(flag) ⇒ Boolean
Input flag.
-
#plain_text=(value) ⇒ String
Input text.
-
#property_values_json ⇒ Hash{String (frozen)->Object
].
-
#strikethrough=(flag) ⇒ Boolean
Input flag.
-
#underline=(flag) ⇒ Boolean
Input flag.
Constructor Details
#initialize(type, options = {}) ⇒ TextObject
8 9 10 11 12 13 14 15 16 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 8 def initialize(type, = {}) if instance_of?(RichTextObject) raise StandardError, "RichTextObject is abstract class. Please use TextObject." end @type = type = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 17 def end |
#will_update ⇒ Object (readonly)
Returns the value of attribute will_update.
17 18 19 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 17 def will_update @will_update end |
Class Method Details
.create_from_json(json) ⇒ Object
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"] = (json["annotations"] || {}).merge(json.slice("plain_text", "href")) case type when "text" TextObject.new json["plain_text"], when "equation" EquationObject.new json["equation"]["expression"], when "mention" mention = json["mention"] case mention["type"] when "user" MentionObject.new .merge({"user_id" => mention["user"]["id"]}) when "page" MentionObject.new .merge({"page_id" => mention["page"]["id"]}) when "database" MentionObject.new .merge({"database_id" => mention["database"]["id"]}) when "date" MentionObject.new .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 .merge({"template_mention" => template_mention["template_mention_date"]}) else MentionObject.new .merge({"template_mention" => template_mention["template_mention_user"]}) end when "link_preview" MentionObject.new .merge({"link_preview" => mention["link_preview"]["url"]}) else raise StandardError, "Unknown mention type: #{mention["type"]}" end else raise StandardError, json end end |
.text_object(to) ⇒ NotionRubyMapping::RichTextObject
58 59 60 61 62 63 64 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 58 def self.text_object(to) if to.is_a? RichTextObject to else TextObject.new to end end |
Instance Method Details
#bold=(flag) ⇒ Boolean
91 92 93 94 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 91 def bold=(flag) @will_update = true ["bold"] = flag end |
#code=(flag) ⇒ Boolean
119 120 121 122 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 119 def code=(flag) @will_update = true ["code"] = flag end |
#color=(color) ⇒ String
126 127 128 129 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 126 def color=(color) @will_update = true ["color"] = color end |
#href=(url) ⇒ String
78 79 80 81 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 78 def href=(url) @will_update = true ["href"] = url end |
#italic=(flag) ⇒ Boolean
98 99 100 101 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 98 def italic=(flag) @will_update = true ["italic"] = flag end |
#plain_text=(value) ⇒ String
85 86 87 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 85 def plain_text=(value) text(value) end |
#property_values_json ⇒ Hash{String (frozen)->Object
67 68 69 70 71 72 73 74 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 67 def property_values_json { "type" => @type, @type => partial_property_values_json, "plain_text" => ["plain_text"], "href" => ["href"], }.merge annotations_json end |
#strikethrough=(flag) ⇒ Boolean
105 106 107 108 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 105 def strikethrough=(flag) @will_update = true ["strikethrough"] = flag end |
#underline=(flag) ⇒ Boolean
112 113 114 115 |
# File 'lib/notion_ruby_mapping/objects/rich_text_object.rb', line 112 def underline=(flag) @will_update = true ["underline"] = flag end |