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, #will_update

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, create_from_json, #database?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #type, #update_property_schema_json

Constructor Details

#initialize(name, will_update: false, base_type: :page, json: nil, people: nil) ⇒ PeopleProperty

Returns a new instance of PeopleProperty.

Parameters:

  • name (String)
  • json (Hash) (defaults to: nil)
  • people (Array) (defaults to: nil)

    ids for people



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 45

def initialize(name, will_update: false, base_type: :page, json: nil, people: nil)
  super name, will_update: will_update, base_type: base_type
  @json = if database?
            {}
          elsif people
            Array(people).map { |uo| UserObject.user_object(uo) }
          elsif json
            json.map { |p| UserObject.new json: p }
          else
            []
          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

#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.

Parameters:

  • people (Hash)

Returns:

  • (Array, nil)

    replaced array

See Also:



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

Returns created json.

Returns:

  • (Hash)

    created json



61
62
63
64
65
66
67
68
69
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 61

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

#update_from_json(json) ⇒ Hash, Array

Parameters:

  • json (Array)

Returns:

  • (Hash, Array)


73
74
75
76
# File 'lib/notion_ruby_mapping/properties/people_property.rb', line 73

def update_from_json(json)
  @will_update = false
  @json = database? ? {} : json["people"].map { |p_json| UserObject.new json: p_json }
end