Class: NotionToMd::PageProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_to_md/page_property.rb

Direct Known Subclasses

NotionToMd::Page::CustomProperty

Class Method Summary collapse

Class Method Details

.checkbox(prop) ⇒ Object



66
67
68
69
70
# File 'lib/notion_to_md/page_property.rb', line 66

def checkbox(prop)
  prop[:checkbox].nil? ? nil : prop[:checkbox].to_s
rescue NoMethodError
  nil
end

.date(prop) ⇒ Object

date type properties not supported:

  • end

  • time_zone



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/notion_to_md/page_property.rb', line 75

def date(prop)
  date = prop.dig(:date, :start)

  case date
  when Date
    date.to_time
  when String
    Time.parse(date)
  else
    date # Time or nil
  end
rescue NoMethodError
  nil
end

.email(prop) ⇒ Object



60
61
62
63
64
# File 'lib/notion_to_md/page_property.rb', line 60

def email(prop)
  prop[:email]
rescue NoMethodError
  nil
end

.emoji(prop) ⇒ Object



18
19
20
21
22
# File 'lib/notion_to_md/page_property.rb', line 18

def emoji(prop)
  prop[:emoji]
rescue NoMethodError
  nil
end

.external(prop) ⇒ Object



12
13
14
15
16
# File 'lib/notion_to_md/page_property.rb', line 12

def external(prop)
  prop.dig(:external, :url)
rescue NoMethodError
  nil
end

.file(prop) ⇒ Object



6
7
8
9
10
# File 'lib/notion_to_md/page_property.rb', line 6

def file(prop)
  prop.dig(:file, :url)
rescue NoMethodError
  nil
end

.files(prop) ⇒ Object



42
43
44
45
46
# File 'lib/notion_to_md/page_property.rb', line 42

def files(prop)
  prop[:files].map { |f| file(f) || external(f) }
rescue NoMethodError
  nil
end

.multi_select(prop) ⇒ Object



24
25
26
27
28
# File 'lib/notion_to_md/page_property.rb', line 24

def multi_select(prop)
  prop[:multi_select].map { |sel| sel[:name] }
rescue NoMethodError
  nil
end

.number(prop) ⇒ Object



54
55
56
57
58
# File 'lib/notion_to_md/page_property.rb', line 54

def number(prop)
  prop[:number]
rescue NoMethodError
  nil
end

.people(prop) ⇒ Object



36
37
38
39
40
# File 'lib/notion_to_md/page_property.rb', line 36

def people(prop)
  prop[:people].map { |sel| sel[:name] }
rescue NoMethodError
  nil
end

.phone_number(prop) ⇒ Object



48
49
50
51
52
# File 'lib/notion_to_md/page_property.rb', line 48

def phone_number(prop)
  prop[:phone_number]
rescue NoMethodError
  nil
end

.rich_text(prop) ⇒ Object



96
97
98
99
100
101
# File 'lib/notion_to_md/page_property.rb', line 96

def rich_text(prop)
  text = prop[:rich_text].map { |text| text[:plain_text] }.join
  text.blank? ? nil : text.dump
rescue NoMethodError
  nil
end

.select(prop) ⇒ Object



30
31
32
33
34
# File 'lib/notion_to_md/page_property.rb', line 30

def select(prop)
  prop.dig(:select, :name).dump
rescue NoMethodError
  nil
end

.url(prop) ⇒ Object



90
91
92
93
94
# File 'lib/notion_to_md/page_property.rb', line 90

def url(prop)
  prop[:url]
rescue NoMethodError
  nil
end