blob: 4d58edee04c2c360323a7584fd7e7ae30da2642d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
require 'cgi'
module Gitlab
module Docs
class Element
def initialize(name, attributes)
@name = name
@attributes = attributes
end
def link?
@name == 'a' && !href.to_s.empty?
end
def has_id?
!id.to_s.empty?
end
def href
@href ||= self.class.decode(attribute('href'))
end
def id
@id ||= attribute('id')&.downcase
end
def self.decode(name)
return if name.to_s.empty?
CGI.unescape(name)
end
private
def attribute(name)
@attributes.to_a
.find { |attr| attr.first == name }
.to_a.last
end
end
end
end
|