Class: NotionRubyMapping::PeopleProperty

Inherits:
MultiProperty show all
Defined in:
lib/notion_ruby_mapping/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

create_from_json, #make_filter_query, #type

Constructor Details

#initialize(name, will_update: false, 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



11
12
13
14
15
16
17
18
19
20
# File 'lib/notion_ruby_mapping/people_property.rb', line 11

def initialize(name, will_update: false, json: nil, people: nil)
  super name, will_update: will_update
  @people = if people
              Array(people).map { |uo| UserObject.user_object(uo) }
            elsif json
              json.map { |p| UserObject.new json: p }
            else
              []
            end
end

Instance Method Details

#people=(people) ⇒ Array?

Returns settled array.

Parameters:

  • people (Hash)

Returns:

  • (Array, nil)

    settled array



40
41
42
43
# File 'lib/notion_ruby_mapping/people_property.rb', line 40

def people=(people)
  @will_update = true
  @people = people ? Array(people).map { |uo| UserObject.user_object(uo) } : []
end

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



23
24
25
26
27
28
29
30
# File 'lib/notion_ruby_mapping/people_property.rb', line 23

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

#update_from_json(json) ⇒ Object

Parameters:

  • json (Hash)


33
34
35
36
# File 'lib/notion_ruby_mapping/people_property.rb', line 33

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