Class: NotionRubyMapping::FileObject

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_ruby_mapping/objects/file_object.rb

Overview

TextObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: nil, json: {}) ⇒ TextObject

Parameters:

  • url (String) (defaults to: nil)

8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 8

def initialize(url: nil, json: {})
  if url
    @type = "external"
    @url = url
  elsif json
    @type = json["type"]
    @url = json[@type]["url"]
    @expiry_time = json[@type]["expiry_time"]
  else
    raise StandardError, "FileObject requires url: or json:"
  end
  @will_update = false
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.


21
22
23
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 21

def type
  @type
end

#urlObject

Returns the value of attribute url.


21
22
23
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 21

def url
  @url
end

#will_updateObject (readonly)

Returns the value of attribute will_update.


21
22
23
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 21

def will_update
  @will_update
end

Class Method Details

.file_object(url_or_fo) ⇒ FileObject

Returns self or created FileObject.


26
27
28
29
30
31
32
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 26

def self.file_object(url_or_fo)
  if url_or_fo.is_a? FileObject
    url_or_fo
  else
    FileObject.new url: url_or_fo
  end
end

Instance Method Details

#external?TrueClass, FalseClass

Returns true if “type” is “external”.

Returns:

  • (TrueClass, FalseClass)

    true if “type” is “external”


35
36
37
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 35

def external?
  @type == "external"
end

#property_values_jsonHash

Returns:

  • (Hash)

49
50
51
52
53
54
55
56
57
58
# File 'lib/notion_ruby_mapping/objects/file_object.rb', line 49

def property_values_json
  ans = {
    "type" => @type,
    @type => {
      "url" => @url,
    },
  }
  ans[@type]["expiry_time"] = @expiry_time if @expiry_time
  ans
end