Class: NotionRubyMapping::MultiSelectProperty

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

Overview

MultiSelect property

Constant Summary collapse

TYPE =
"multi_select"

Instance Attribute Summary

Attributes inherited from Property

#name, #property_cache, #property_id, #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_data_source_property, #assert_database_or_data_source_property, #assert_database_property, #assert_page_property, #clear_will_update, #contents?, create_from_json, #data_source?, #database?, #database_or_data_source?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #retrieve_page_property, #type, #update_from_json

Constructor Details

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



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 64

def initialize(name, will_update: false, base_type: "page", json: nil, multi_select: nil,
               property_id: nil, property_cache: nil)
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
              property_cache: property_cache
  if database_or_data_source?
    @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_option(name:, color:) ⇒ Array

Returns added array.



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

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

#edit_multi_select_optionsArray



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

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

#multi_selectArray, Hash



13
14
15
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 13

def multi_select
  @json
end

#multi_select=(multi_select) ⇒ Array?



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

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

#multi_select_namesArray



18
19
20
21
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 18

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

#multi_select_optionsArray



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

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

#property_values_jsonHash



93
94
95
96
97
98
99
100
101
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 93

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

#update_property_schema_jsonHash



79
80
81
82
83
84
85
86
87
88
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 79

def update_property_schema_json
  assert_database_or_data_source_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