Class: NotionRubyMapping::RichTextArray
- Inherits:
-
Object
- Object
- NotionRubyMapping::RichTextArray
- Includes:
- Enumerable
- Defined in:
- lib/notion_ruby_mapping/controllers/rich_text_array.rb
Overview
RichTextObject
Instance Attribute Summary collapse
-
#will_update ⇒ TrueClass, FalseClass
True if it will update.
Class Method Summary collapse
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
- #rich_text_objects=(text_info) ⇒ Object
- #update_property_schema_json(flag = false) ⇒ Object
Constructor Details
#initialize(key, json: nil, text_objects: nil, will_update: false) ⇒ RichTextArray
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/notion_ruby_mapping/controllers/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 Attribute Details
#will_update ⇒ TrueClass, FalseClass
100 101 102 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 100 def will_update @will_update || @rich_text_objects.map(&:will_update).any? end |
Class Method Details
.rich_text_array(key, text_objects = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 24 def self.rich_text_array(key, text_objects = nil) if text_objects.nil? RichTextArray.new key elsif text_objects.is_a? RichTextArray text_objects else RichTextArray.new key, text_objects: text_objects end end |
Instance Method Details
#<<(to) ⇒ NotionRubyMapping::RichTextObject
36 37 38 39 40 41 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 36 def <<(to) @will_update = true rto = RichTextObject.text_object(to) @rich_text_objects << rto rto end |
#[](index) ⇒ RichTextObject
45 46 47 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 45 def [](index) @rich_text_objects[index] end |
#create_from_json(json = []) ⇒ Array
51 52 53 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 51 def create_from_json(json = []) json.map { |rt_json| RichTextObject.create_from_json rt_json } end |
#delete_at(index) ⇒ NotionRubyMapping::RichTextObject
57 58 59 60 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 57 def delete_at(index) @will_update = true @rich_text_objects.delete_at index end |
#each(&block) ⇒ Enumerator
64 65 66 67 68 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 64 def each(&block) return enum_for(:each) unless block @rich_text_objects.each(&block) end |
#full_text ⇒ String
71 72 73 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 71 def full_text map(&:text).join "" end |
#property_schema_json ⇒ Object
91 92 93 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 91 def property_schema_json will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {} end |
#property_values_json ⇒ Object
87 88 89 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 87 def property_values_json will_update ? @rich_text_objects.map(&:property_values_json) : [] end |
#rich_text_objects=(text_info) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 76 def rich_text_objects=(text_info) @will_update = true @rich_text_objects = if text_info.is_a? RichTextArray text_info.filter { true } else Array(text_info).map do |to| RichTextObject.text_object to end end end |
#update_property_schema_json(flag = false) ⇒ Object
95 96 97 |
# File 'lib/notion_ruby_mapping/controllers/rich_text_array.rb', line 95 def update_property_schema_json(flag = false) flag || will_update ? {@key => @rich_text_objects.map(&:property_values_json)} : {} end |