Class: NotionRubyMapping::FormulaProperty

Inherits:
DateBaseProperty show all
Includes:
ContainsDoesNotContain, GreaterThanLessThan, StartsWithEndsWith
Defined in:
lib/notion_ruby_mapping/properties/formula_property.rb

Overview

Formula property

Constant Summary collapse

TYPE =
"formula"

Instance Attribute Summary

Attributes inherited from Property

#name, #property_cache, #property_id, #will_update

Instance Method Summary collapse

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 StartsWithEndsWith

#filter_ends_with, #filter_starts_with

Methods included from ContainsDoesNotContain

#filter_contains, #filter_does_not_contain

Methods inherited from DateBaseProperty

date_from_obj, #filter_after, #filter_before, #filter_does_not_equal, #filter_equals, #filter_next_month, #filter_next_week, #filter_next_year, #filter_on_or_after, #filter_on_or_before, #filter_past_month, #filter_past_week, #filter_past_year, #filter_this_week, start_end_time, value_str, #value_str

Methods included from IsEmptyIsNotEmpty

#filter_is_empty, #filter_is_not_empty

Methods inherited from Property

#assert_database_property, #assert_page_property, #clear_will_update, #contents?, create_from_json, #database?, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #retrieve_page_property, #type, #update_from_json

Constructor Details

#initialize(name, will_update: false, base_type: "page", json: nil, formula: nil, property_id: nil, property_cache: nil) ⇒ FormulaProperty

Returns a new instance of FormulaProperty.

Parameters:

  • name (String, Symbol)
  • json (Hash) (defaults to: nil)


44
45
46
47
48
49
50
51
52
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 44

def initialize(name, will_update: false, base_type: "page", json: nil, formula: nil, property_id: nil,
               property_cache: nil)
  super name, will_update: will_update, base_type: base_type, property_id: property_id,
              property_cache: property_cache
  @json = json || {}
  return unless database?

  @json["expression"] = formula if formula
end

Instance Method Details

#formulaHash



17
18
19
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 17

def formula
  @json
end

#formula_expressionString

Returns formula_expression.



25
26
27
28
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 25

def formula_expression
  assert_database_property __method__
  @json["expression"]
end

#formula_expression=(f_e) ⇒ Object



32
33
34
35
36
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 32

def formula_expression=(f_e)
  assert_database_property __method__
  @will_update = true
  @json["expression"] = f_e
end

#property_values_jsonHash

Page property only methods

Returns:

  • (Hash)


69
70
71
72
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 69

def property_values_json
  assert_page_property __method__
  {}
end

#update_property_schema_jsonHash

Returns:

  • (Hash)


57
58
59
60
61
62
63
64
65
# File 'lib/notion_ruby_mapping/properties/formula_property.rb', line 57

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

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