Class: NotionRubyMapping::PeopleProperty

Inherits:
MultiProperty show all
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

Instance Method Summary collapse

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_cache: nil, query: nil) ⇒ PeopleProperty



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 49

def initialize(name, will_update: false, base_type: :page, json: nil, people: nil, property_cache: nil, query: nil)
  super name, will_update: will_update, base_type: base_type, 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
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 42

def self.people_from_json(json)
  List.new(json: json, property: self).select { true }
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

#peopleArray, 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_jsonHash



65
66
67
68
69
70
71
72
73
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 65

def property_values_json
  assert_page_property __method__
  {
    @name => {
      "type" => "people",
      "people" => @json.map(&:property_values_json),
    },
  }
end

#update_from_json(json) ⇒ Hash, Array



77
78
79
80
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 77

def update_from_json(json)
  @will_update = false
  @json = database? ? {} : PeopleProperty.people_from_json(json)
end