Class: NotionRubyMapping::RichTextArray
- Inherits:
-
Object
- Object
- NotionRubyMapping::RichTextArray
- Includes:
- Enumerable
- Defined in:
- lib/notion_ruby_mapping/rich_text_array.rb
Overview
RichTextObject
Instance Method Summary collapse
-
#<<(to) ⇒ NotionRubyMapping::RichTextObject
Added RichTextObject.
-
#[](index) ⇒ RichTextObject
Selected RichTextObject.
-
#create_from_json(json = []) ⇒ Array
RichTextArray.
-
#delete_at(index) ⇒ NotionRubyMapping::RichTextObject
Removed RichTextObject.
- #each(&block) ⇒ Enumerator
- #full_text ⇒ String
-
#initialize(key, json: nil, text_objects: nil, will_update: false) ⇒ RichTextArray
constructor
A new instance of RichTextArray.
- #property_schema_json ⇒ Object
- #property_values_json ⇒ Object
- #update_property_schema_json ⇒ Object
-
#will_update ⇒ TrueClass, FalseClass
True if it will update.
Constructor Details
#initialize(key, json: nil, text_objects: nil, will_update: false) ⇒ RichTextArray
Returns a new instance of RichTextArray.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 9 def initialize(key, json: nil, text_objects: nil, will_update: false) @key = key @rich_text_objects = if json create_from_json(json) elsif text_objects Array(text_objects).map do |to| RichTextObject.text_object to end else [] end @will_update = will_update end |
Instance Method Details
#<<(to) ⇒ NotionRubyMapping::RichTextObject
Returns added RichTextObject.
68 69 70 71 72 73 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 68 def <<(to) @will_update = true rto = RichTextObject.text_object(to) @rich_text_objects << rto rto end |
#[](index) ⇒ RichTextObject
Returns selected RichTextObject.
77 78 79 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 77 def [](index) @rich_text_objects[index] end |
#create_from_json(json = []) ⇒ Array
Returns RichTextArray.
25 26 27 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 25 def create_from_json(json = []) json.map { |rt_json| RichTextObject.create_from_json rt_json } end |
#delete_at(index) ⇒ NotionRubyMapping::RichTextObject
Returns removed RichTextObject.
31 32 33 34 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 31 def delete_at(index) @will_update = true @rich_text_objects.delete_at index end |
#each(&block) ⇒ Enumerator
38 39 40 41 42 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 38 def each(&block) return enum_for(:each) unless block @rich_text_objects.each(&block) end |
#full_text ⇒ String
45 46 47 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 45 def full_text map(&:text).join "" end |
#property_schema_json ⇒ Object
53 54 55 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 53 def property_schema_json will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {} end |
#property_values_json ⇒ Object
49 50 51 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 49 def property_values_json will_update ? @rich_text_objects.map(&:property_values_json) : [] end |
#update_property_schema_json ⇒ Object
57 58 59 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 57 def update_property_schema_json will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {} end |
#will_update ⇒ TrueClass, FalseClass
Returns true if it will update.
62 63 64 |
# File 'lib/notion_ruby_mapping/rich_text_array.rb', line 62 def will_update @will_update || @rich_text_objects.map(&:will_update).any? end |