Class: NotionRubyMapping::MultiSelectProperty
- Inherits:
-
MultiProperty
- Object
- Property
- MultiProperty
- NotionRubyMapping::MultiSelectProperty
- 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
-
#add_multi_select_option(name:, color:) ⇒ Array
Added array.
-
#edit_multi_select_options ⇒ Array
Copyed multi select options.
-
#initialize(name, will_update: false, base_type: "page", json: nil, multi_select: nil, property_id: nil, property_cache: nil) ⇒ MultiSelectProperty
constructor
A new instance of MultiSelectProperty.
- #multi_select ⇒ Array, Hash
-
#multi_select=(multi_select) ⇒ Array?
Settled array.
- #multi_select_names ⇒ Array
- #multi_select_options ⇒ Array
-
#property_values_json ⇒ Hash
Created json.
- #update_property_schema_json ⇒ Hash
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, #contents?, create_from_json, #database?, #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
Returns a new instance of 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? @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:) << {"name" => name, "color" => color} end |
#edit_multi_select_options ⇒ Array
Returns copyed multi select options.
34 35 36 37 38 |
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 34 def assert_database_property __method__ @will_update = true @json["options"] ||= [] end |
#multi_select ⇒ Array, 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?
Returns settled 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_names ⇒ Array
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_options ⇒ Array
42 43 44 45 |
# File 'lib/notion_ruby_mapping/properties/multi_select_property.rb', line 42 def assert_database_property __method__ @json["options"] || [] end |
#property_values_json ⇒ Hash
Returns created json.
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_json ⇒ Hash
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_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 |