Class: NotionRubyMapping::FilesProperty

Inherits:
Property
  • Object
show all
Includes:
IsEmptyIsNotEmpty
Defined in:
lib/notion_ruby_mapping/files_property.rb

Overview

Select property

Constant Summary collapse

TYPE =
"files"

Instance Attribute Summary

Attributes inherited from Property

#name, #will_update

Instance Method Summary collapse

Methods included from IsEmptyIsNotEmpty

#filter_is_empty, #filter_is_not_empty

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, #update_property_schema_json

Constructor Details

#initialize(name, will_update: false, base_type: :page, json: nil, files: []) ⇒ FilesProperty

Returns a new instance of FilesProperty.

Parameters:

  • name (String)

    Property name

  • files (String) (defaults to: [])

    files value (optional)



31
32
33
34
35
36
37
38
39
# File 'lib/notion_ruby_mapping/files_property.rb', line 31

def initialize(name, will_update: false, base_type: :page, json: nil, files: [])
  super name, will_update: will_update, base_type: base_type
  if database?
    @json = json || {}
  else
    @json = json || []
    @json = Array(files).map { |url| url_to_hash url } unless files.empty?
  end
end

Instance Method Details

#filesHash

Returns:

  • (Hash)


14
15
16
# File 'lib/notion_ruby_mapping/files_property.rb', line 14

def files
  @json
end

#files=(files = []) ⇒ Object

Page property only methods



20
21
22
23
# File 'lib/notion_ruby_mapping/files_property.rb', line 20

def files=(files = [])
  @will_update = true
  @json = Array(files).map { |url| url_to_hash url }
end

#property_values_jsonHash

Returns:

  • (Hash)


42
43
44
45
46
47
48
49
# File 'lib/notion_ruby_mapping/files_property.rb', line 42

def property_values_json
  assert_page_property __method__
  if @json.map { |f| f["type"] }.include? "file"
    {}
  else
    {@name => {"files" => @json, "type" => "files"}}
  end
end