Class: NotionRubyMapping::Property
- Inherits:
-
Object
- Object
- NotionRubyMapping::Property
- Defined in:
- lib/notion_ruby_mapping/properties/property.rb
Overview
abstract class for property
Direct Known Subclasses
CheckboxProperty, DateBaseProperty, EmailProperty, FilesProperty, MultiProperty, NumberProperty, PhoneNumberProperty, SelectProperty, TextProperty, UrlProperty
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Common methods.
-
#will_update ⇒ Object
readonly
Common methods.
Class Method Summary collapse
-
.create_from_json(name, input_json, base_type = :page) ⇒ NotionRubyMapping::Property?
Generated Property object.
Instance Method Summary collapse
- #assert_database_property(method) ⇒ Object
- #assert_page_property(method) ⇒ Object
- #clear_will_update ⇒ FalseClass
-
#database? ⇒ TrueClass, FalseClass
True if database property.
-
#initialize(name, will_update: false, base_type: :page) ⇒ Property
constructor
Generated Property object.
-
#make_filter_query(key, value, rollup = nil, rollup_type = nil) ⇒ NotionRubyMapping::Query
Generated Query object.
- #new_name=(new_name) ⇒ Object
-
#page? ⇒ TrueClass, FalseClass
True if page property.
- #property_schema_json ⇒ Hash
-
#property_values_json ⇒ Hash
{} created_time cannot be updated.
-
#remove ⇒ NotionRubyMapping::Property
Self.
-
#type ⇒ Symbol
Property type.
- #update_from_json(json) ⇒ Object
- #update_property_schema_json ⇒ Hash
Constructor Details
#initialize(name, will_update: false, base_type: :page) ⇒ Property
Returns generated Property object.
35 36 37 38 39 40 41 42 43 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 35 def initialize(name, will_update: false, base_type: :page) @name = name @will_update = will_update @base_type = base_type @create = false @remove = false @new_name = nil @json = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Common methods
10 11 12 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 10 def name @name end |
#will_update ⇒ Object (readonly)
Common methods
10 11 12 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 10 def will_update @will_update end |
Class Method Details
.create_from_json(name, input_json, base_type = :page) ⇒ NotionRubyMapping::Property?
Returns generated Property object.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 48 def self.create_from_json(name, input_json, base_type = :page) raise StandardError, "Property not found: #{name}:#{input_json}" if input_json.nil? type = input_json["type"] klass = { "checkbox" => CheckboxProperty, "created_time" => CreatedTimeProperty, "date" => DateProperty, "formula" => FormulaProperty, "last_edited_time" => LastEditedTimeProperty, "rollup" => RollupProperty, "email" => EmailProperty, "files" => FilesProperty, "created_by" => CreatedByProperty, "last_edited_by" => LastEditedByProperty, "multi_select" => MultiSelectProperty, "people" => PeopleProperty, "relation" => RelationProperty, "number" => NumberProperty, "phone_number" => PhoneNumberProperty, "select" => SelectProperty, "title" => TitleProperty, "rich_text" => RichTextProperty, "url" => UrlProperty, }[type] raise StandardError, "Irregular property type: #{type}" unless klass klass.new name, json: input_json[type], base_type: base_type end |
Instance Method Details
#assert_database_property(method) ⇒ Object
122 123 124 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 122 def assert_database_property(method) raise StandardError, "#{method} can execute only Database property." unless database? end |
#assert_page_property(method) ⇒ Object
147 148 149 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 147 def assert_page_property(method) raise StandardError, "#{method} can execute only Page property." unless @base_type == :page end |
#clear_will_update ⇒ FalseClass
79 80 81 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 79 def clear_will_update @will_update = false end |
#database? ⇒ TrueClass, FalseClass
Returns true if database property.
84 85 86 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 84 def database? @base_type == :database end |
#make_filter_query(key, value, rollup = nil, rollup_type = nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 91 def make_filter_query(key, value, rollup = nil, rollup_type = nil) if rollup Query.new filter: {"property" => @name, rollup => {rollup_type => {key => value}}} elsif rollup_type Query.new filter: {"property" => @name, rollup_type => {key => value}} elsif @name == "__timestamp__" Query.new filter: {"timestamp" => type, type => {key => value}} else Query.new filter: {"property" => @name, type => {key => value}} end end |
#new_name=(new_name) ⇒ Object
15 16 17 18 19 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 15 def new_name=(new_name) assert_database_property __method__ @will_update = true @new_name = new_name end |
#page? ⇒ TrueClass, FalseClass
Returns true if page property.
104 105 106 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 104 def page? @base_type == :page end |
#property_schema_json ⇒ Hash
127 128 129 130 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 127 def property_schema_json assert_database_property __method__ {@name => {type => property_schema_json_sub}} end |
#property_values_json ⇒ Hash
Returns {} created_time cannot be updated.
154 155 156 157 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 154 def property_values_json assert_page_property __method__ {} end |
#remove ⇒ NotionRubyMapping::Property
Returns self.
22 23 24 25 26 27 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 22 def remove assert_database_property __method__ @will_update = true @remove = true self end |
#type ⇒ Symbol
Returns property type.
115 116 117 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 115 def type self.class::TYPE end |
#update_from_json(json) ⇒ Object
109 110 111 112 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 109 def update_from_json(json) @will_update = false @json = json[type] end |
#update_property_schema_json ⇒ Hash
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/notion_ruby_mapping/properties/property.rb', line 133 def update_property_schema_json assert_database_property __method__ if @remove {@name => nil} elsif @new_name {@name => {"name" => @new_name}} else {} end end |