Class: NotionRubyMapping::Payload
- Inherits:
-
Object
- Object
- NotionRubyMapping::Payload
- Defined in:
- lib/notion_ruby_mapping/controllers/payload.rb
Overview
Payload class
Instance Method Summary collapse
-
#clear ⇒ Hash
{}.
-
#initialize(json) ⇒ Payload
constructor
A new instance of Payload.
- #merge_property(json) ⇒ Object
-
#property_schema_json(*others) ⇒ Hash
Created json.
-
#property_values_json(*others) ⇒ Hash
Created json.
-
#set_icon(emoji: nil, url: nil) ⇒ NotionRubyMapping::Payload
Updated Payload.
-
#update_property_schema_json(*others) ⇒ Hash
Created json.
Constructor Details
#initialize(json) ⇒ Payload
Returns a new instance of Payload.
6 7 8 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 6 def initialize(json) @json = json || {} end |
Instance Method Details
#clear ⇒ Hash
Returns {}.
50 51 52 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 50 def clear @json = {} end |
#merge_property(json) ⇒ Object
26 27 28 29 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 26 def merge_property(json) @json["properties"] ||= {} @json["properties"].merge!(json) end |
#property_schema_json(*others) ⇒ Hash
Returns created json.
39 40 41 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 39 def property_schema_json(*others) others.compact.reduce({}) { |hash, o| hash.merge o.property_schema_json }.merge @json end |
#property_values_json(*others) ⇒ Hash
Returns created json.
33 34 35 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 33 def property_values_json(*others) others.compact.reduce({}) { |hash, o| hash.merge o.property_values_json }.merge @json end |
#set_icon(emoji: nil, url: nil) ⇒ NotionRubyMapping::Payload
Returns updated Payload.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 13 def set_icon(emoji: nil, url: nil) payload = if emoji {"type" => "emoji", "emoji" => emoji} elsif url {"type" => "external", "external" => {"url" => url}} else {} end @json["icon"] = payload self end |
#update_property_schema_json(*others) ⇒ Hash
Returns created json.
45 46 47 |
# File 'lib/notion_ruby_mapping/controllers/payload.rb', line 45 def update_property_schema_json(*others) others.compact.reduce({}) { |hash, o| hash.merge o.update_property_schema_json }.merge @json end |