Class: RubyRich::Transcript::Entry
- Inherits:
-
Object
- Object
- RubyRich::Transcript::Entry
- Defined in:
- lib/ruby_rich/transcript.rb
Instance Attribute Summary collapse
-
#collapsed ⇒ Object
Returns the value of attribute collapsed.
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #append(delta) ⇒ Object
- #cache_fetch(cache_key) ⇒ Object
-
#initialize(id:, type:, content: "", metadata: {}, status: nil, collapsed: false, name: nil) ⇒ Entry
constructor
A new instance of Entry.
- #replace(new_content) ⇒ Object
- #text ⇒ Object
- #text=(value) ⇒ Object
- #to_h ⇒ Object
- #update {|_self| ... } ⇒ Object
Constructor Details
#initialize(id:, type:, content: "", metadata: {}, status: nil, collapsed: false, name: nil) ⇒ Entry
Returns a new instance of Entry.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_rich/transcript.rb', line 23 def initialize(id:, type:, content: "", metadata: {}, status: nil, collapsed: false, name: nil) @id = id @type = type @content = +content.to_s @metadata = .dup @status = status @collapsed = collapsed @name = name @version = 0 @render_cache = {} end |
Instance Attribute Details
#collapsed ⇒ Object
Returns the value of attribute collapsed.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def collapsed @collapsed end |
#content ⇒ Object
Returns the value of attribute content.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def id @id end |
#metadata ⇒ Object
Returns the value of attribute metadata.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
20 21 22 |
# File 'lib/ruby_rich/transcript.rb', line 20 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
21 22 23 |
# File 'lib/ruby_rich/transcript.rb', line 21 def version @version end |
Instance Method Details
#[](key) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ruby_rich/transcript.rb', line 85 def [](key) case key.to_sym when :text, :content @content when :id @id when :type @type when :metadata @metadata when :status @status when :collapsed @collapsed when :name @name else @metadata[key] || @metadata[key.to_sym] || @metadata[key.to_s] end end |
#[]=(key, value) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ruby_rich/transcript.rb', line 106 def []=(key, value) case key.to_sym when :text, :content replace(value) when :type @type = value touch when :metadata @metadata = value || {} touch when :status @status = value touch when :collapsed @collapsed = value touch when :name @name = value touch else @metadata[key] = value touch end end |
#append(delta) ⇒ Object
67 68 69 70 71 |
# File 'lib/ruby_rich/transcript.rb', line 67 def append(delta) @content << delta.to_s touch self end |
#cache_fetch(cache_key) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/ruby_rich/transcript.rb', line 131 def cache_fetch(cache_key) versioned_key = [@version, cache_key] return @render_cache[versioned_key] if @render_cache.key?(versioned_key) @render_cache.clear @render_cache[versioned_key] = yield end |
#replace(new_content) ⇒ Object
73 74 75 76 77 |
# File 'lib/ruby_rich/transcript.rb', line 73 def replace(new_content) @content = +new_content.to_s touch self end |
#text ⇒ Object
35 36 37 |
# File 'lib/ruby_rich/transcript.rb', line 35 def text @content end |
#text=(value) ⇒ Object
39 40 41 |
# File 'lib/ruby_rich/transcript.rb', line 39 def text=(value) replace(value) end |
#to_h ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ruby_rich/transcript.rb', line 139 def to_h { id: @id, type: @type, text: @content, content: @content, metadata: @metadata, status: @status, collapsed: @collapsed, name: @name }.compact end |
#update {|_self| ... } ⇒ Object
79 80 81 82 83 |
# File 'lib/ruby_rich/transcript.rb', line 79 def update yield self touch self end |