Class: NotionRubyMapping::Property

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

Overview

abstract class for property

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, will_update: false) ⇒ Property

Returns generated Property object.

Parameters:

  • name (String)

    Property name



8
9
10
11
# File 'lib/notion_ruby_mapping/property.rb', line 8

def initialize(name, will_update: false)
  @name = name
  @will_update = will_update
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#will_updateTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


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

def will_update
  @will_update
end

Class Method Details

.create_from_json(name, input_json) ⇒ NotionRubyMapping::Property?

Returns generated Property object.

Parameters:

  • name (String)
  • input_json (Hash)

Returns:

Raises:

  • (StandardError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/notion_ruby_mapping/property.rb', line 36

def self.create_from_json(name, input_json)
  raise StandardError, "Property not found: #{name}:#{input_json}" if input_json.nil?

  case input_json["type"]
  when "number"
    NumberProperty.new name, number: input_json["number"]
  when "select"
    SelectProperty.new name, json: input_json["select"]
  when "multi_select"
    MultiSelectProperty.new name, json: input_json["multi_select"]
  when "date"
    DateProperty.new name, json: input_json["date"]
  when "title"
    TitleProperty.new name, json: input_json["title"]
  when "rich_text"
    RichTextProperty.new name, json: input_json["rich_text"]
  when "checkbox"
    CheckboxProperty.new name, checkbox: input_json["checkbox"]
  when "people"
    PeopleProperty.new name, json: input_json["people"]
  when "email"
    EmailProperty.new name, email: input_json["email"]
  when "url"
    UrlProperty.new name, url: input_json["url"]
  when "phone_number"
    PhoneNumberProperty.new name, phone_number: input_json["phone_number"]
  when "files"
    FilesProperty.new name, json: input_json["files"]
  when "created_time"
    CreatedTimeProperty.new name, created_time: input_json["created_time"]
  when "last_edited_time"
    LastEditedTimeProperty.new name, last_edited_time: input_json["last_edited_time"]
  when "created_by"
    CreatedByProperty.new name, json: input_json["created_by"]
  when "last_edited_by"
    LastEditedByProperty.new name, json: input_json["last_edited_by"]
  when "formula"
    FormulaProperty.new name, json: input_json["formula"]
  when "rollup"
    RollupProperty.new name, json: input_json["rollup"]
  when "relation"
    RelationProperty.new name, json: input_json["relation"]
  else
    raise StandardError, "Irregular property type: #{input_json["type"]}"
  end
end

Instance Method Details

#make_filter_query(key, value, rollup = nil, rollup_type = nil) ⇒ NotionRubyMapping::Query

Returns generated Query object.

Parameters:

  • key (String)

    query parameter

  • value (Object)

    query value

Returns:



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

def make_filter_query(key, value, rollup = nil, rollup_type = nil)
  if rollup
    Query.new filter: {"property" => @name, rollup => {rollup_type => {key => value}}}
  else
    Query.new filter: {"property" => @name, type => {key => value}}
  end
end

#typeSymbol

Returns property type.

Returns:

  • (Symbol)

    property type



29
30
31
# File 'lib/notion_ruby_mapping/property.rb', line 29

def type
  self.class::TYPE
end