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 collapse

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

create_from_json, #make_filter_query, #type

Constructor Details

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

Returns a new instance of FilesProperty.

Parameters:

  • name (String)

    Property name

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

    files value (optional)



11
12
13
14
# File 'lib/notion_ruby_mapping/files_property.rb', line 11

def initialize(name, will_update: false, json: nil, files: [])
  super name, will_update: will_update
  @files = json || Array(files).map { |url| url_to_hash url } || []
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



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

def files
  @files
end

Instance Method Details

#property_values_jsonHash

Returns:

  • (Hash)


36
37
38
39
40
41
42
# File 'lib/notion_ruby_mapping/files_property.rb', line 36

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

#update_from_json(json) ⇒ Object

Parameters:

  • json (Hash)


30
31
32
33
# File 'lib/notion_ruby_mapping/files_property.rb', line 30

def update_from_json(json)
  @will_update = false
  @files = json["files"]
end

#url_to_hash(url) ⇒ Hash

Parameters:

  • url (String)

Returns:

  • (Hash)


19
20
21
22
23
24
25
26
27
# File 'lib/notion_ruby_mapping/files_property.rb', line 19

def url_to_hash(url)
  {
    "name" => url,
    "type" => "external",
    "external" => {
      "url" => url,
    },
  }
end