Class: NotionRubyMapping::TextProperty
- Extended by:
- Forwardable
- Includes:
- Enumerable, ContainsDoesNotContain, EqualsDoesNotEqual, IsEmptyIsNotEmpty, StartsWithEndsWith
- Defined in:
- lib/notion_ruby_mapping/properties/text_property.rb
Overview
Text property
Direct Known Subclasses
Constant Summary collapse
- TYPE =
"text"
Instance Attribute Summary collapse
-
#text_objects ⇒ Object
readonly
Page property only methods.
Attributes inherited from Property
#name, #property_cache, #property_id
Class Method Summary collapse
Instance Method Summary collapse
-
#clear ⇒ Object
Removes all rich text objects.
- #clear_will_update ⇒ FalseClass
-
#initialize(name, will_update: false, base_type: "page", json: nil, text_objects: nil, property_id: nil, property_cache: nil, query: nil) ⇒ TextProperty
constructor
A new instance of TextProperty.
-
#plain_text=(text) ⇒ Object
Replaces all rich text objects with a single plain text object.
-
#property_values_json ⇒ Hash
Created json.
- #update_from_json(json) ⇒ Object
-
#will_update ⇒ TrueClass, FalseClass
Will update?.
Methods included from IsEmptyIsNotEmpty
#filter_is_empty, #filter_is_not_empty
Methods included from StartsWithEndsWith
#filter_ends_with, #filter_starts_with
Methods included from ContainsDoesNotContain
#filter_contains, #filter_does_not_contain
Methods included from EqualsDoesNotEqual
#filter_does_not_equal, #filter_equals
Methods inherited from Property
#assert_data_source_property, #assert_database_or_data_source_property, #assert_page_property, create_from_json, #data_source?, #database?, #database_or_data_source?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #retrieve_page_property, #type, #update_property_schema_json
Constructor Details
#initialize(name, will_update: false, base_type: "page", json: nil, text_objects: nil, property_id: nil, property_cache: nil, query: nil) ⇒ TextProperty
Returns a new instance of TextProperty.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 31 def initialize(name, will_update: false, base_type: "page", json: nil, text_objects: nil, property_id: nil, property_cache: nil, query: nil) raise StandardError, "TextObject is abstract class. Please use RichTextProperty." if instance_of? TextProperty super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache, query: query @text_objects = if database_or_data_source? json || {} else RichTextArray.new self.class::TYPE, json: json, text_objects: text_objects end end |
Instance Attribute Details
#text_objects ⇒ Object (readonly)
Page property only methods
20 21 22 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 20 def text_objects @text_objects end |
Class Method Details
.rich_text_array_from_json(json) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 44 def self.rich_text_array_from_json(json) if json["object"] == "list" rich_text_objects = List.new(json: json, type: "property", value: self).select { true } RichTextArray.rich_text_array self::TYPE, rich_text_objects else RichTextArray.new self::TYPE, json: json[self::TYPE] end end |
Instance Method Details
#clear ⇒ Object
Removes all rich text objects.
This method makes the property value an empty rich text array.
95 96 97 98 99 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 95 def clear assert_page_property __method__ @text_objects.clear @will_update = true end |
#clear_will_update ⇒ FalseClass
102 103 104 105 106 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 102 def clear_will_update super @text_objects.clear_will_update if page? false end |
#plain_text=(text) ⇒ Object
Replaces all rich text objects with a single plain text object.
This method does not preserve annotations, links, mentions, or equations.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 71 def plain_text=(text) assert_page_property __method__ raise ArgumentError if text.nil? @text_objects = RichTextArray.new( self.class::TYPE, text_objects: text, ) @will_update = true end |
#property_values_json ⇒ Hash
Returns created json.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 54 def property_values_json assert_page_property __method__ text_json = @text_objects.map(&:property_values_json) { @name => { "type" => self.class::TYPE, self.class::TYPE => text_json.empty? ? (@json || []) : text_json, }, } end |
#update_from_json(json) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 83 def update_from_json(json) @will_update = false if database_or_data_source? @json = json[self.class::TYPE] || {} else @text_objects = self.class.rich_text_array_from_json json end end |
#will_update ⇒ TrueClass, FalseClass
Returns will update?.
109 110 111 |
# File 'lib/notion_ruby_mapping/properties/text_property.rb', line 109 def will_update @will_update || (page? && @text_objects.will_update) end |