Class: NotionRubyMapping::DateProperty

Inherits:
DateBaseProperty show all
Defined in:
lib/notion_ruby_mapping/date_property.rb

Overview

DateProperty

Constant Summary collapse

TYPE =
"date"

Instance Attribute Summary

Attributes inherited from Property

#name, #will_update

Instance Method Summary collapse

Methods inherited from DateBaseProperty

#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

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, start_date: nil, end_date: nil, time_zone: nil) ⇒ DateProperty

Returns a new instance of DateProperty.

Parameters:

  • name (String)
  • json (Hash) (defaults to: nil)
  • start_date (Date, Time, DateTime, String, nil) (defaults to: nil)
  • end_date (Date, Time, DateTime, String, nil) (defaults to: nil)
  • time_zone (String, nil) (defaults to: nil)


13
14
15
16
17
18
# File 'lib/notion_ruby_mapping/date_property.rb', line 13

def initialize(name, will_update: false, json: nil, start_date: nil, end_date: nil, time_zone: nil)
  super name, will_update: will_update
  @start_date = start_date || json && json["start"]
  @end_date = end_date || json && json["end"]
  @time_zone = time_zone || json && json["time_zone"]
end

Instance Method Details

#end_date=(end_date) ⇒ Date, ...

Parameters:

  • end_date (Date, Time, DateTime, String)

Returns:

  • (Date, Time, DateTime, String)


45
46
47
48
49
50
# File 'lib/notion_ruby_mapping/date_property.rb', line 45

def end_date=(end_date)
  @will_update = true
  @end_date = end_date
  @end_date = nil if @start_date.class != @end_date.class || @start_date > @end_date
  @end_date
end

#property_values_jsonHash

Returns created json.

Returns:

  • (Hash)

    created json



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/notion_ruby_mapping/date_property.rb', line 21

def property_values_json
  {
    @name => {
      "type" => "date",
      "date" => {
        "start" => value_str(@start_date),
        "end" => value_str(@end_date),
        "time_zone" => @time_zone,
      },
    },
  }
end

#start_date=(start_date) ⇒ Date, ...

Parameters:

  • start_date (Date, Time, DateTime, String)

Returns:

  • (Date, Time, DateTime, String)


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

def start_date=(start_date)
  @will_update = true
  @start_date = start_date
  @end_date = nil if @start_date.class != @end_date.class || @start_date > @end_date
  @start_date
end

#time_zone=(time_zone) ⇒ Array?

Returns settled array.

Parameters:

  • time_zone (String)

Returns:

  • (Array, nil)

    settled array



54
55
56
57
# File 'lib/notion_ruby_mapping/date_property.rb', line 54

def time_zone=(time_zone)
  @will_update = true
  @time_zone = time_zone
end

#update_from_json(json) ⇒ Object

Parameters:

  • json (Hash)


60
61
62
63
64
65
66
# File 'lib/notion_ruby_mapping/date_property.rb', line 60

def update_from_json(json)
  @will_update = false
  jd = json["date"]
  @start_date = jd["start"]
  @end_date = jd["end"]
  @time_zone = jd["time_zone"]
end