Class: NotionRubyMapping::RelationProperty

Inherits:
MultiProperty show all
Defined in:
lib/notion_ruby_mapping/relation_property.rb

Overview

MultiSelect property

Constant Summary collapse

TYPE =
"relation"

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, relation: nil) ⇒ RelationProperty

Returns a new instance of RelationProperty.

Parameters:

  • name (String)
  • json (Hash) (defaults to: nil)
  • relation (String, Array<String>) (defaults to: nil)


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

def initialize(name, will_update: false, json: nil, relation: nil)
  super name, will_update: will_update
  @relation = if relation
                Array(relation)
              elsif json
                json.map { |r| r["id"] }
              else
                []
              end
end

Instance Method Details

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



36
37
38
39
40
41
42
43
# File 'lib/notion_ruby_mapping/relation_property.rb', line 36

def property_values_json
  {
    @name => {
      "type" => "relation",
      "relation" => @relation.map { |rid| {"id" => rid} },
    },
  }
end

#relation=(relation) ⇒ Array<String>

Returns settled relation Array.

Parameters:

  • relation (String, Array<String>)

    a id or Array of id

Returns:

  • (Array<String>)

    settled relation Array



24
25
26
27
# File 'lib/notion_ruby_mapping/relation_property.rb', line 24

def relation=(relation)
  @will_update = true
  @relation = Array(relation)
end

#update_from_json(json) ⇒ Object

Parameters:

  • json (Hash)


30
31
32
33
# File 'lib/notion_ruby_mapping/relation_property.rb', line 30

def update_from_json(json)
  @will_update = false
  @relation = json["relation"].map { |r| r["id"] }
end