Class: RicherText::Nodes::Mention

Inherits:
RicherText::Node show all
Defined in:
lib/richer_text/nodes/mention.rb

Constant Summary

Constants inherited from RicherText::Node

RicherText::Node::STYLES

Instance Attribute Summary

Attributes inherited from RicherText::Node

#attrs, #children, #json, #type

Instance Method Summary collapse

Methods inherited from RicherText::Node

build, #style

Constructor Details

#initialize(json) ⇒ Mention

Returns a new instance of Mention.



4
5
6
7
# File 'lib/richer_text/nodes/mention.rb', line 4

def initialize(json)
  @marks = json.fetch("marks", []).map { |mark| RicherText::Mark.new(mark) }
  super(json)
end

Instance Method Details

#accept(visitor) ⇒ Object



9
10
11
# File 'lib/richer_text/nodes/mention.rb', line 9

def accept(visitor)
  visitor.visit_mention(self, @marks)
end

#avatar_urlObject



25
26
27
# File 'lib/richer_text/nodes/mention.rb', line 25

def avatar_url
  @user.respond_to?(:avatar_url) ? @user.avatar_url : @attrs["avatarUrl"]
end

#idObject



17
18
19
# File 'lib/richer_text/nodes/mention.rb', line 17

def id
  @attrs["id"]
end

#nameObject



21
22
23
# File 'lib/richer_text/nodes/mention.rb', line 21

def name
  @user.respond_to?(:name) ? @user.name : @attrs["label"]
end

#userObject



13
14
15
# File 'lib/richer_text/nodes/mention.rb', line 13

def user
  @user ||= GlobalID::Locator.locate(@attrs["id"])
end