Class: NotionRubyMapping::RichTextObject
- Inherits:
-
Object
- Object
- NotionRubyMapping::RichTextObject
- Defined in:
- lib/notion_ruby_mapping/rich_text_object.rb
Overview
RichTextObject
Direct Known Subclasses
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.
- #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/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 @options = end |
Class Method Details
.create_from_json(json) ⇒ Object
18 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 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 18 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 "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 else raise StandardError, "Unknown mention type: #{mention["type"]}" end else raise StandardError, json end end |
.text_object(to) ⇒ NotionRubyMapping::RichTextObject
Returns RichTextObject.
53 54 55 56 57 58 59 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 53 def self.text_object(to) if to.is_a? RichTextObject to else TextObject.new to end end |
Instance Method Details
#bold=(flag) ⇒ Boolean
Returns input flag.
79 80 81 82 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 79 def bold=(flag) @will_update = true @options["bold"] = flag end |
#code=(flag) ⇒ Boolean
Returns input flag.
107 108 109 110 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 107 def code=(flag) @will_update = true @options["code"] = flag end |
#color=(color) ⇒ String
Returns input color.
114 115 116 117 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 114 def color=(color) @will_update = true @options["color"] = color end |
#italic=(flag) ⇒ Boolean
Returns input flag.
86 87 88 89 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 86 def italic=(flag) @will_update = true @options["italic"] = flag end |
#plain_text=(value) ⇒ String
Returns input text.
73 74 75 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 73 def plain_text=(value) text(value) end |
#property_values_json ⇒ Hash{String (frozen)->Object
Returns ].
62 63 64 65 66 67 68 69 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 62 def property_values_json { "type" => @type, @type => partial_property_values_json, "plain_text" => @options["plain_text"], "href" => @options["href"], }.merge annotations_json end |
#strikethrough=(flag) ⇒ Boolean
Returns input flag.
93 94 95 96 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 93 def strikethrough=(flag) @will_update = true @options["strikethrough"] = flag end |
#underline=(flag) ⇒ Boolean
Returns input flag.
100 101 102 103 |
# File 'lib/notion_ruby_mapping/rich_text_object.rb', line 100 def underline=(flag) @will_update = true @options["underline"] = flag end |