notion_to_md 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b181c658f60d77ec9e3564ee70ac9cc59d4288512a8617386251c708404fe65
4
- data.tar.gz: e540275064b3873031fb48ea57d076039b79ec7e518b0644019b293916e7d5c4
3
+ metadata.gz: 2afa81a1825a9ebf8efaa1759908803baa3e556fabeccd464d75be001016fd05
4
+ data.tar.gz: 7d72ae2095612e43e54147d8c23d6d8eb7f4d7c3c4dec0e5ce3e91d311c31347
5
5
  SHA512:
6
- metadata.gz: d8902cc80c1237de34d2bb3c351be176a13117d0fe3a15ff009c5205bdc0850102268a230e7f152a4eb1622523ffd7988b29f3ca48bb0dbf0f2aaa97711b151d
7
- data.tar.gz: e90cac1fdaf6955310841678285a4ac8dff267042052e8adf14f8bd0623b2dbf2a6c8a5c8ac6625674fee6998e30bea624c111483c96b56f876e189477e4899a
6
+ metadata.gz: 246785dfc4372f8ac87f1e51c955402f297293ff2092ce19d4fed7a8ba57664d10ad8b87f62d5252ce05842d7a660633aff9593b7b0335271503a2ccc04c748e
7
+ data.tar.gz: 52765f8dbcaa3e81064aa29111f2d13957f1eee7ba638f301e44776e21088b4311ed45a2db5e97b6f3c1e7684384b963e45f6d7a2de15575ca0f4639ea5eaa2f
@@ -16,11 +16,11 @@ module NotionToMd
16
16
  end
17
17
 
18
18
  def cover
19
- page.dig(:cover, :external, :url)
19
+ PageProperty.external(page[:cover]) || PageProperty.file(page[:cover])
20
20
  end
21
21
 
22
22
  def icon
23
- page.dig(:icon, :file, :url) || page.dig(:icon, :emoji)
23
+ PageProperty.emoji(page[:icon]) || PageProperty.external(page[:icon]) || PageProperty.file(page[:icon])
24
24
  end
25
25
 
26
26
  def id
@@ -51,8 +51,8 @@ module NotionToMd
51
51
  @frontmatter ||= <<~CONTENT
52
52
  ---
53
53
  #{props.to_a.map do |k, v|
54
- "#{k}: #{v}"
55
- end.join("\n")}
54
+ "#{k}: #{v}"
55
+ end.join("\n")}
56
56
  ---
57
57
  CONTENT
58
58
  end
@@ -85,55 +85,9 @@ module NotionToMd
85
85
  }
86
86
  end
87
87
 
88
- class CustomProperty
89
- class << self
90
- def multi_select(prop)
91
- prop.multi_select.map(&:name)
92
- end
93
-
94
- def select(prop)
95
- prop['select']&.name
96
- end
97
-
98
- def people(prop)
99
- prop.people.map(&:name)
100
- end
101
-
102
- def files(prop)
103
- prop.files.map { |f| f.file.url }
104
- end
105
-
106
- def phone_number(prop)
107
- prop.phone_number
108
- end
109
-
110
- def number(prop)
111
- prop.number
112
- end
113
-
114
- def email(prop)
115
- prop.email
116
- end
117
-
118
- def checkbox(prop)
119
- prop.checkbox.to_s
120
- end
121
-
122
- # date type properties not supported:
123
- # - end
124
- # - time_zone
125
- def date(prop)
126
- prop.date.start
127
- end
128
-
129
- def url(prop)
130
- prop.url
131
- end
132
-
133
- def rich_text(prop)
134
- prop.rich_text.map(&:plain_text).join
135
- end
136
- end
88
+ # This class is kept for retro compatibility reasons.
89
+ # Use instead the PageProperty class.
90
+ class CustomProperty < PageProperty
137
91
  end
138
92
  end
139
93
  end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionToMd
4
+ class PageProperty
5
+ class << self
6
+ def file(prop)
7
+ prop.dig(:file, :url)
8
+ rescue NoMethodError
9
+ nil
10
+ end
11
+
12
+ def external(prop)
13
+ prop.dig(:external, :url)
14
+ rescue NoMethodError
15
+ nil
16
+ end
17
+
18
+ def emoji(prop)
19
+ prop[:emoji]
20
+ rescue NoMethodError
21
+ nil
22
+ end
23
+
24
+ def multi_select(prop)
25
+ prop[:multi_select].map { |sel| sel[:name] }
26
+ rescue NoMethodError
27
+ nil
28
+ end
29
+
30
+ def select(prop)
31
+ prop.dig(:select, :name)
32
+ rescue NoMethodError
33
+ nil
34
+ end
35
+
36
+ def people(prop)
37
+ prop[:people].map { |sel| sel[:name] }
38
+ rescue NoMethodError
39
+ nil
40
+ end
41
+
42
+ def files(prop)
43
+ prop[:files].map { |f| file(f) || external(f) }
44
+ rescue NoMethodError
45
+ nil
46
+ end
47
+
48
+ def phone_number(prop)
49
+ prop[:phone_number]
50
+ rescue NoMethodError
51
+ nil
52
+ end
53
+
54
+ def number(prop)
55
+ prop[:number]
56
+ rescue NoMethodError
57
+ nil
58
+ end
59
+
60
+ def email(prop)
61
+ prop[:email]
62
+ rescue NoMethodError
63
+ nil
64
+ end
65
+
66
+ def checkbox(prop)
67
+ prop[:checkbox].nil? ? nil : prop[:checkbox].to_s
68
+ rescue NoMethodError
69
+ nil
70
+ end
71
+
72
+ # date type properties not supported:
73
+ # - end
74
+ # - time_zone
75
+ def date(prop)
76
+ prop.dig(:date, :start)
77
+ rescue NoMethodError
78
+ nil
79
+ end
80
+
81
+ def url(prop)
82
+ prop[:url]
83
+ rescue NoMethodError
84
+ nil
85
+ end
86
+
87
+ def rich_text(prop)
88
+ prop[:rich_text].map { |text| text[:plain_text] }.join
89
+ rescue NoMethodError
90
+ nil
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionToMd
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
data/lib/notion_to_md.rb CHANGED
@@ -7,6 +7,7 @@ require 'active_support/core_ext/object/blank'
7
7
  require_relative './notion_to_md/version'
8
8
  require_relative './notion_to_md/converter'
9
9
  require_relative './notion_to_md/logger'
10
+ require_relative './notion_to_md/page_property'
10
11
  require_relative './notion_to_md/page'
11
12
  require_relative './notion_to_md/blocks'
12
13
  require_relative './notion_to_md/text'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_to_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-03 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -124,6 +124,7 @@ files:
124
124
  - lib/notion_to_md/converter.rb
125
125
  - lib/notion_to_md/logger.rb
126
126
  - lib/notion_to_md/page.rb
127
+ - lib/notion_to_md/page_property.rb
127
128
  - lib/notion_to_md/text.rb
128
129
  - lib/notion_to_md/text_annotation.rb
129
130
  - lib/notion_to_md/version.rb