class Beret::Block
Attributes
block_json[R]
id[R]
parent[R]
Public Class Methods
new(block_json, options={})
click to toggle source
# File lib/beret/block.rb, line 8 def initialize(block_json, options={}) @id = SecureRandom.uuid @block_json = block_json @parent = options[:parent] end
Public Instance Methods
attributes()
click to toggle source
# File lib/beret/block.rb, line 14 def attributes @attributes ||= block_json[content_key] end
children()
click to toggle source
# File lib/beret/block.rb, line 30 def children @children ||= begin block_json[children_key] && block_json[children_key].map do |block| Block.new(block, parent: self) end end end
to_json()
click to toggle source
# File lib/beret/block.rb, line 38 def to_json {}.tap do |json| json[type_key] = block_json[type_key] json[content_key] = attributes if children json[children_key] = children.map(&:to_json) end end end
type()
click to toggle source
# File lib/beret/block.rb, line 26 def type block_json[type_key] end
update_attribute(field_name, value)
click to toggle source
# File lib/beret/block.rb, line 18 def update_attribute(field_name, value) @attributes[field_name.to_s] = value end
update_content(new_content)
click to toggle source
# File lib/beret/block.rb, line 22 def update_content(new_content) @attributes = Hash(new_content) end
Private Instance Methods
children_key()
click to toggle source
# File lib/beret/block.rb, line 53 def children_key "blocks" end
content_key()
click to toggle source
# File lib/beret/block.rb, line 57 def content_key "content" end
type_key()
click to toggle source
# File lib/beret/block.rb, line 61 def type_key "type" end