Class: Metanorma::Mirror::Model::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/mirror/model/node.rb

Direct Known Subclasses

Container, Leaf

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, attrs: {}) ⇒ Node

Returns a new instance of Node.



9
10
11
12
# File 'lib/metanorma/mirror/model/node.rb', line 9

def initialize(type:, attrs: {})
  @type = type
  @attrs = normalize_attrs(attrs)
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



7
8
9
# File 'lib/metanorma/mirror/model/node.rb', line 7

def attrs
  @attrs
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/metanorma/mirror/model/node.rb', line 7

def type
  @type
end

Instance Method Details

#accept_rewriter(_rewriter) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
35
# File 'lib/metanorma/mirror/model/node.rb', line 32

def accept_rewriter(_rewriter)
  raise NotImplementedError,
        "#{self.class}#accept_rewriter not implemented"
end

#container?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/metanorma/mirror/model/node.rb', line 24

def container?
  false
end

#leaf?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/metanorma/mirror/model/node.rb', line 20

def leaf?
  false
end

#text_contentObject



28
29
30
# File 'lib/metanorma/mirror/model/node.rb', line 28

def text_content
  ""
end

#to_hObject



14
15
16
17
18
# File 'lib/metanorma/mirror/model/node.rb', line 14

def to_h
  h = { "type" => type }
  h["attrs"] = @attrs.dup unless @attrs.empty?
  h
end