Class: NotionRubyMapping::PeopleProperty
- Inherits:
-
MultiProperty
- Object
- Property
- MultiProperty
- NotionRubyMapping::PeopleProperty
- Defined in:
- lib/notion_ruby_mapping/properties/people_property.rb
Overview
PeopleProperty class
Constant Summary collapse
- TYPE =
"people"
Instance Attribute Summary
Attributes inherited from Property
#name, #property_cache, #property_id, #will_update
Class Method Summary collapse
-
.people_from_json(json) ⇒ Object
Common methods.
Instance Method Summary collapse
- #add_person(user_id_or_uo) ⇒ Array<UserObject>
-
#initialize(name, will_update: false, base_type: "page", json: nil, people: nil, property_id: nil, property_cache: nil, query: nil) ⇒ PeopleProperty
constructor
A new instance of PeopleProperty.
- #people ⇒ Array, Hash
-
#people=(people) ⇒ Array?
Replaced array.
-
#property_values_json ⇒ Hash
Created json.
- #update_from_json(json) ⇒ Hash, Array
Methods included from IsEmptyIsNotEmpty
#filter_is_empty, #filter_is_not_empty
Methods included from ContainsDoesNotContain
#filter_contains, #filter_does_not_contain
Methods inherited from Property
#assert_database_property, #assert_page_property, #clear_will_update, #contents?, create_from_json, #database?, #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, people: nil, property_id: nil, property_cache: nil, query: nil) ⇒ PeopleProperty
Returns a new instance of PeopleProperty.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 55 def initialize(name, will_update: false, base_type: "page", json: nil, people: nil, property_id: nil, property_cache: nil, query: nil) super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache, query: query @json = if database? {} elsif people Array(people).map { |uo| UserObject.user_object(uo) } elsif json PeopleProperty.people_from_json json else [] end end |
Class Method Details
.people_from_json(json) ⇒ Object
Common methods
42 43 44 45 46 47 48 49 50 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 42 def self.people_from_json(json) if json.is_a? Array json.map { |sub_json| UserObject.new json: sub_json } elsif json["object"] == "list" List.new(json: json, type: "property", value: self).select { true } else json["people"].map { |sub_json| UserObject.new json: sub_json } end end |
Instance Method Details
#add_person(user_id_or_uo) ⇒ Array<UserObject>
23 24 25 26 27 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 23 def add_person(user_id_or_uo) assert_page_property __method__ @will_update = true @json << UserObject.user_object(user_id_or_uo) end |
#people ⇒ Array, Hash
14 15 16 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 14 def people @json end |
#people=(people) ⇒ Array?
Returns replaced array.
32 33 34 35 36 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 32 def people=(people) assert_page_property __method__ @will_update = true @json = people ? Array(people).map { |uo| UserObject.user_object(uo) } : [] end |
#property_values_json ⇒ Hash
Returns created json.
73 74 75 76 77 78 79 80 81 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 73 def property_values_json assert_page_property __method__ { @name => { "type" => "people", "people" => @json.map(&:property_values_json), }, } end |
#update_from_json(json) ⇒ Hash, Array
85 86 87 88 |
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 85 def update_from_json(json) @will_update = false @json = database? ? {} : PeopleProperty.people_from_json(json) end |