Class: NotionRubyMapping::SelectProperty

Inherits:
Property
  • Object
show all
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

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.

Parameters:

  • name (String, Symbol)

    Property name

  • json (Hash) (defaults to: nil)
  • select (String) (defaults to: nil)

    String value (optional)



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.

Parameters:

  • name (String)
  • color (String)

Returns:

  • (Array)

    added array

See Also:



35
36
37
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 35

def add_select_option(name:, color:)
  edit_select_options << {"name" => name, "color" => color}
end

#edit_select_optionsArray

Returns copyed multi select options.

Returns:

  • (Array)

    copyed multi select options



40
41
42
43
44
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 40

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

#property_values_jsonHash

Returns:

  • (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

#selectHash



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_nameString



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_namesString



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_optionsArray



48
49
50
51
# File 'lib/notion_ruby_mapping/properties/select_property.rb', line 48

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

#update_property_schema_jsonHash

Returns:

  • (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