Class: NotionRubyMapping::FilesProperty
- Includes:
- IsEmptyIsNotEmpty
- Defined in:
- lib/notion_ruby_mapping/properties/files_property.rb
Overview
Select property
Constant Summary collapse
- TYPE =
"files"
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
Attributes inherited from Property
Instance Method Summary collapse
-
#initialize(name, will_update: false, base_type: :page, json: nil, files: []) ⇒ FilesProperty
constructor
A new instance of FilesProperty.
- #property_values_json ⇒ Hash
- #update_from_json(json) ⇒ Object
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_property_schema_json
Constructor Details
#initialize(name, will_update: false, base_type: :page, json: nil, files: []) ⇒ FilesProperty
Returns a new instance of FilesProperty.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/notion_ruby_mapping/properties/files_property.rb', line 28 def initialize(name, will_update: false, base_type: :page, json: nil, files: []) super name, will_update: will_update, base_type: base_type if database? @files = json || {} elsif json @files = json.map { |sub_json| FileObject.new json: sub_json } @file_names = json.map { |sub_json| sub_json["name"] } elsif !files.empty? @files = Array(files).map { |url| FileObject.file_object url } @file_names = Array(files) else @files = [] end end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
9 10 11 |
# File 'lib/notion_ruby_mapping/properties/files_property.rb', line 9 def files @files end |
Instance Method Details
#property_values_json ⇒ Hash
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/notion_ruby_mapping/properties/files_property.rb', line 44 def property_values_json assert_page_property __method__ if @files.map(&:type).include? "file" {} else files = @files.map(&:property_values_json) @file_names&.each_with_index { |name, i| files[i]["name"] = name } {@name => {"files" => files, "type" => "files"}} end end |
#update_from_json(json) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/notion_ruby_mapping/properties/files_property.rb', line 55 def update_from_json(json) return if database? @files = json["files"].map { |sub_json| FileObject.new json: sub_json } @file_names = json["files"].map { |sub_json| sub_json["name"] } @will_update = false p self end |