Class: NotionRubyMapping::MultiSelectProperty
- Inherits:
-
MultiProperty
- Object
- Property
- MultiProperty
- NotionRubyMapping::MultiSelectProperty
- 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
Instance Method Summary collapse
-
#add_multi_select_options(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) ⇒ 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, 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.
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.
30 31 32 |
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 30 def (name:, color:) << {"name" => name, "color" => color} end |
#edit_multi_select_options ⇒ Array
Returns copyed multi select options.
35 36 37 38 39 |
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 35 def assert_database_property __method__ @will_update = true @json["options"] ||= [] end |
#multi_select ⇒ 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.
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_names ⇒ 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_options ⇒ Array
42 43 44 45 |
# File 'lib/notion_ruby_mapping/multi_select_property.rb', line 42 def assert_database_property __method__ @json["options"] || [] end |
#property_values_json ⇒ Hash
Returns 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_json ⇒ 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 |