Class: NotionRubyMapping::PropertyCache
- Inherits:
-
Object
- Object
- NotionRubyMapping::PropertyCache
- Defined in:
- lib/notion_ruby_mapping/property_cache.rb
Instance Method Summary collapse
-
#[](key) ⇒ Property
Property for key.
- #add_property(property, will_update: false) ⇒ Object
-
#create_json ⇒ Hash
Created json.
-
#initialize(json = {}) ⇒ PropertyCache
constructor
A new instance of PropertyCache.
Constructor Details
#initialize(json = {}) ⇒ PropertyCache
Returns a new instance of PropertyCache.
3 4 5 6 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 3 def initialize(json = {}) @properties = {} @json = json end |
Instance Method Details
#[](key) ⇒ Property
Returns Property for key.
10 11 12 13 14 15 16 17 18 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 10 def [](key) ans = @properties[key] unless ans if @json && @json[key] @properties[key] = Property.create_from_json key, @json[key] end end @properties[key] end |
#add_property(property, will_update: false) ⇒ Object
22 23 24 25 26 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 22 def add_property(property, will_update: false) @properties[property.name] = property property.will_update = true if will_update self end |
#create_json ⇒ Hash
Returns created json.
29 30 31 32 33 34 35 36 |
# File 'lib/notion_ruby_mapping/property_cache.rb', line 29 def create_json @properties.each_with_object({}) do |(key, property), ans| if property.will_update ans["properties"] ||= {} ans["properties"][key] = property.create_json end end end |