Class: NotionRubyMapping::StatusProperty

Inherits:
Property
  • Object
show all
Includes:
EqualsDoesNotEqual, IsEmptyIsNotEmpty
Defined in:
lib/notion_ruby_mapping/properties/status_property.rb

Overview

Status property

Constant Summary collapse

TYPE =
"status"

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_data_source_property, #assert_database_or_data_source_property, #assert_page_property, #clear_will_update, 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", property_id: nil, property_cache: nil, json: {}) ⇒ StatusProperty

Returns a new instance of StatusProperty.

Parameters:

  • name (String, Symbol)

    Property name

  • json (Boolean, Hash) (defaults to: {})


71
72
73
74
75
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 71

def initialize(name, will_update: false, base_type: "page", property_id: nil, property_cache: nil, json: {})
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
              property_cache: property_cache
  @json = json
end

Instance Method Details

#add_status_option(name:, color:, group: nil) ⇒ Array<Hash>

Database or DataSource property only methods

Parameters:

  • name (String)
  • color (String)

Returns:

  • (Array<Hash>)

    updated status options



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

def add_status_option(name:, color:, group: nil)
  hash = {"name" => name, "color" => color}
  hash["group"] = group if group
  edit_status_options << hash
end

#edit_status_optionsArray<Hash>

Returns editable status options.

Returns:

  • (Array<Hash>)

    editable status options



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

def edit_status_options
  assert_database_or_data_source_property __method__
  @will_update = true
  @json["edit_options"] ||= []
end

#property_schema_json_subHash

Returns:

  • (Hash)


102
103
104
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 102

def property_schema_json_sub
  @json["edit_options"] ? {"options" => @json["edit_options"]} : {}
end

#property_values_jsonHash

Returns:

  • (Hash)


80
81
82
83
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 80

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

#statusObject



15
16
17
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 15

def status
  @json
end

#status=(status) ⇒ Object



30
31
32
33
34
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 30

def status=(status)
  assert_page_property __method__
  @will_update = true
  @json = {"name" => status}
end

#status_nameString



23
24
25
26
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 23

def status_name
  assert_page_property __method__
  @json["name"]
end

#status_namesArray<String>

Returns status option names.

Returns:

  • (Array<String>)

    status option names



60
61
62
63
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 60

def status_names
  assert_database_or_data_source_property __method__
  status_options.map { |s| s["name"] }
end

#status_optionsArray<Hash>

Returns status options.

Returns:

  • (Array<Hash>)

    status options



54
55
56
57
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 54

def status_options
  assert_database_or_data_source_property __method__
  @json["options"] || []
end

#update_property_schema_jsonHash

Returns:

  • (Hash)


88
89
90
91
92
93
94
95
96
97
# File 'lib/notion_ruby_mapping/properties/status_property.rb', line 88

def update_property_schema_json
  assert_database_or_data_source_property __method__
  ans = super
  return ans if ans != {} || !@will_update

  ans[@name] ||= {}
  ans[@name]["status"] ||= {}
  ans[@name]["status"]["options"] = @json["edit_options"]
  ans
end