Class: NotionRubyMapping::SelectProperty
- Includes:
- EqualsDoesNotEqual, IsEmptyIsNotEmpty
- Defined in:
- lib/notion_ruby_mapping/properties/select_property.rb
Overview
Select property
Constant Summary collapse
- TYPE =
"select"
Instance Attribute Summary
Attributes inherited from Property
#name, #property_cache, #property_id, #will_update
Instance Method Summary collapse
-
#add_select_option(name:, color:) ⇒ Array
Added array.
-
#edit_select_options ⇒ Array
Copyed multi select options.
-
#initialize(name, will_update: false, base_type: "page", json: nil, select: nil, property_id: nil, property_cache: nil) ⇒ SelectProperty
constructor
A new instance of SelectProperty.
- #property_values_json ⇒ Hash
- #select ⇒ Hash
- #select=(select) ⇒ Object
- #select_name ⇒ String
- #select_names ⇒ String
- #select_options ⇒ Array
- #update_property_schema_json ⇒ Hash
Methods included from IsEmptyIsNotEmpty
#filter_is_empty, #filter_is_not_empty
Methods included from EqualsDoesNotEqual
#filter_does_not_equal, #filter_equals
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, select: nil, property_id: nil, property_cache: nil) ⇒ SelectProperty
Returns a new instance of SelectProperty.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 77 def initialize(name, will_update: false, base_type: "page", json: nil, 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 @json = if database? json || {"options" => []} else json || {"name" => select} end end |
Instance Method Details
#add_select_option(name:, color:) ⇒ Array
Returns added array.
35 36 37 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 35 def add_select_option(name:, color:) << {"name" => name, "color" => color} end |
#edit_select_options ⇒ Array
Returns copyed multi select options.
40 41 42 43 44 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 40 def assert_database_property __method__ @will_update = true @json["options"] ||= [] end |
#property_values_json ⇒ Hash
105 106 107 108 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 105 def property_values_json assert_page_property __method__ {@name => {"type" => "select", "select" => @json}} end |
#select ⇒ Hash
16 17 18 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 16 def select @json end |
#select=(select) ⇒ Object
64 65 66 67 68 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 64 def select=(select) assert_page_property __method__ @will_update = true @json = {"name" => select} end |
#select_name ⇒ String
24 25 26 27 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 24 def select_name assert_page_property __method__ @json["name"] end |
#select_names ⇒ String
55 56 57 58 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 55 def select_names assert_database_property __method__ @json["options"].map { |s| s["name"] } end |
#select_options ⇒ Array
48 49 50 51 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 48 def assert_database_property __method__ @json["options"] || [] end |
#update_property_schema_json ⇒ Hash
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 91 def update_property_schema_json assert_database_property __method__ ans = super return ans if ans != {} || !@will_update ans[@name] ||= {} ans[@name]["select"] ||= {} ans[@name]["select"]["options"] = @json["options"] ans end |