Class: NotionRubyMapping::NumberProperty

Inherits:
Property
  • Object
show all
Includes:
EqualsDoesNotEqual, GreaterThanLessThan, IsEmptyIsNotEmpty
Defined in:
lib/notion_ruby_mapping/number_property.rb

Overview

Number property

Constant Summary collapse

TYPE =
"number"

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 included from GreaterThanLessThan

#filter_greater_than, #filter_greater_than_or_equal_to, #filter_less_than, #filter_less_than_or_equal_to

Methods included from EqualsDoesNotEqual

#filter_does_not_equal, #filter_equals

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

Constructor Details

#initialize(name, will_update: false, base_type: :page, json: nil, format: nil) ⇒ NumberProperty



52
53
54
55
56
# File 'lib/notion_ruby_mapping/number_property.rb', line 52

def initialize(name, will_update: false, base_type: :page, json: nil, format: nil)
  super name, will_update: will_update, base_type: base_type
  @json = json
  @json ||= {"format" => (format || "number")} if database?
end

Instance Method Details

#formatString



23
24
25
26
# File 'lib/notion_ruby_mapping/number_property.rb', line 23

def format
  assert_database_property __method__
  @json["format"]
end

#format=(format) ⇒ String



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

def format=(format)
  assert_database_property __method__
  @will_update = true
  @json["format"] = format
end

#numberNumeric, Hash



16
17
18
# File 'lib/notion_ruby_mapping/number_property.rb', line 16

def number
  @json
end

#number=(num) ⇒ Numeric



40
41
42
43
44
# File 'lib/notion_ruby_mapping/number_property.rb', line 40

def number=(num)
  assert_page_property __method__
  @will_update = true
  @json = num
end

#property_values_jsonHash



82
83
84
85
# File 'lib/notion_ruby_mapping/number_property.rb', line 82

def property_values_json
  assert_page_property __method__
  {@name => {"number" => @json, "type" => "number"}}
end

#update_from_json(json) ⇒ NotionRubyMapping::NumberProperty



60
61
62
63
64
# File 'lib/notion_ruby_mapping/number_property.rb', line 60

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

#update_property_schema_jsonHash



69
70
71
72
73
74
75
76
77
# File 'lib/notion_ruby_mapping/number_property.rb', line 69

def update_property_schema_json
  assert_database_property __method__
  ans = super
  return ans if ans != {} || !@will_update

  ans[@name] ||= {}
  ans[@name]["number"] = @json
  ans
end