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

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

Constructor Details

#initialize(name, will_update: false, base_type: :page, json: nil, multi_select: nil) ⇒ MultiSelectProperty

Returns a new instance of MultiSelectProperty.

Parameters:

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


63
64
65
66
67
68
69
70
71
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 63

def initialize(name, will_update: false, base_type: :page, json: nil, multi_select: nil)
  super name, will_update: will_update, base_type: base_type
  if database?
    @json = json || {"options" => []}
  else
    @json = json || []
    @json = Array(multi_select).map { |ms| {"name" => ms} } unless multi_select.nil?
  end
end

Instance Method Details

#add_multi_select_options(name:, color:) ⇒ Array

Returns added array.

Parameters:

  • name (String)
  • color (String)

Returns:

  • (Array)

    added array



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

def add_multi_select_options(name:, color:)
  edit_multi_select_options << {"name" => name, "color" => color}
end

#edit_multi_select_optionsArray

Returns copyed multi select options.

Returns:

  • (Array)

    copyed multi select options



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

def edit_multi_select_options
  assert_database_property __method__
  @will_update = true
  @json["options"] ||= []
end

#multi_selectArray, Hash

Returns:

  • (Array, Hash)


15
16
17
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 15

def multi_select
  @json
end

#multi_select=(multi_select) ⇒ Array?

Returns settled array.

Parameters:

  • multi_select (Hash)

Returns:

  • (Array, nil)

    settled array



51
52
53
54
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 51

def multi_select=(multi_select)
  @will_update = true
  @json = multi_select ? Array(multi_select).map { |ms| {"name" => ms} } : []
end

#multi_select_namesArray

Returns:

  • (Array)


20
21
22
23
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 20

def multi_select_names
  mshs = @base_type == :page ? @json : @json["options"]
  mshs.map { |h| h["name"] }
end

#multi_select_optionsArray

Returns:

  • (Array)


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

def multi_select_options
  assert_database_property __method__
  @json["options"] || []
end

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



90
91
92
93
94
95
96
97
98
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 90

def property_values_json
  assert_page_property __method__
  {
    @name => {
      "type" => "multi_select",
      "multi_select" => @json,
    },
  }
end

#update_property_schema_jsonHash

Returns:

  • (Hash)


76
77
78
79
80
81
82
83
84
85
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 76

def update_property_schema_json
  assert_database_property __method__
  ans = super
  return ans if ans != {} || !@will_update

  ans[@name] ||= {}
  ans[@name]["multi_select"] ||= {}
  ans[@name]["multi_select"]["options"] = @json["options"]
  ans
end