Class: Prosereflect::User
- Defined in:
- lib/prosereflect/user.rb
Overview
User class represents a user mention in ProseMirror.
Constant Summary collapse
- PM_TYPE =
'user'
Class Method Summary collapse
Instance Method Summary collapse
-
#add_child ⇒ Object
Override content-related methods since user mentions don’t have content.
- #content ⇒ Object
- #id ⇒ Object
-
#id=(user_id) ⇒ Object
Update the user ID.
-
#initialize(attributes = {}) ⇒ User
constructor
A new instance of User.
- #to_h ⇒ Object
Methods inherited from Node
#find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #text_content, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ User
Returns a new instance of User.
20 21 22 23 24 25 26 27 28 |
# File 'lib/prosereflect/user.rb', line 20 def initialize(attributes = {}) attributes[:content] = [] super return unless attributes[:attrs] @id = attributes[:attrs]['id'] self.attrs = { 'id' => @id } end |
Class Method Details
.create(attrs = nil) ⇒ Object
30 31 32 |
# File 'lib/prosereflect/user.rb', line 30 def self.create(attrs = nil) new(attrs: attrs) end |
Instance Method Details
#add_child ⇒ Object
Override content-related methods since user mentions don’t have content
46 47 48 |
# File 'lib/prosereflect/user.rb', line 46 def add_child(*) raise NotImplementedError, 'User mention nodes cannot have children' end |
#content ⇒ Object
50 51 52 |
# File 'lib/prosereflect/user.rb', line 50 def content [] end |
#id ⇒ Object
41 42 43 |
# File 'lib/prosereflect/user.rb', line 41 def id @id || attrs&.[]('id') end |
#id=(user_id) ⇒ Object
Update the user ID
35 36 37 38 39 |
# File 'lib/prosereflect/user.rb', line 35 def id=(user_id) @id = user_id self.attrs ||= {} attrs['id'] = user_id end |
#to_h ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/prosereflect/user.rb', line 54 def to_h hash = super hash['attrs'] = { 'id' => id } hash['content'] = [] hash end |