Class: NotionRubyMapping::MultiSelectProperty

Inherits:
MultiProperty show all
Includes:
ContainsDoesNotContain, IsEmptyIsNotEmpty
Defined in:
lib/notion_ruby_mapping/multi_select_property.rb

Overview

MultiSelect property

Constant Summary collapse

TYPE =
"multi_select"

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, multi_select: nil) ⇒ MultiSelectProperty

Returns a new instance of MultiSelectProperty.

Parameters:

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


13
14
15
16
17
18
19
20
21
22
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 13

def initialize(name, will_update: false, json: nil, multi_select: nil)
  super name, will_update: will_update
  @multi_select = if multi_select
                    Array(multi_select)
                  elsif json.is_a? Array
                    json.map { |ms| ms["name"] }
                  else
                    []
                  end
end

Instance Method Details

#multi_select=(multi_select) ⇒ Array?

Returns settled array.

Parameters:

  • multi_select (Hash)

Returns:

  • (Array, nil)

    settled array



36
37
38
39
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 36

def multi_select=(multi_select)
  @will_update = true
  @multi_select = multi_select ? Array(multi_select) : []
end

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



25
26
27
28
29
30
31
32
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 25

def property_values_json
  {
    @name => {
      "type" => "multi_select",
      "multi_select" => @multi_select.map { |v| {"name" => v} },
    },
  }
end

#update_from_json(json) ⇒ Object

Parameters:

  • json (Hash)


42
43
44
45
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 42

def update_from_json(json)
  @will_update = false
  @multi_select = json["multi_select"].map { |ms| ms["name"] }
end