Class: Docbook::Mirror::Node::Text

Inherits:
Docbook::Mirror::Node show all
Defined in:
lib/docbook/mirror/node.rb

Overview

Nested classes for all node types

Constant Summary collapse

PM_TYPE =
"text"

Constants inherited from Docbook::Mirror::Node

NODES

Instance Attribute Summary collapse

Attributes inherited from Docbook::Mirror::Node

#attrs, #content, #marks, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Docbook::Mirror::Node

#to_json

Constructor Details

#initialize(text: "") ⇒ Text

Returns a new instance of Text.



76
77
78
79
# File 'lib/docbook/mirror/node.rb', line 76

def initialize(text: "", **)
  super(**)
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



74
75
76
# File 'lib/docbook/mirror/node.rb', line 74

def text
  @text
end

Class Method Details

.from_h(hash) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/docbook/mirror/node.rb', line 91

def self.from_h(hash)
  return nil unless hash

  new(
    text: hash["text"] || "",
    attrs: (hash["attrs"] || {}).transform_keys(&:to_sym),
    marks: (hash["marks"] || []).map do |m|
      Docbook::Mirror::Mark.from_h(m)
    end,
  )
end

Instance Method Details

#text_contentObject



87
88
89
# File 'lib/docbook/mirror/node.rb', line 87

def text_content
  text.to_s
end

#to_hObject



81
82
83
84
85
# File 'lib/docbook/mirror/node.rb', line 81

def to_h
  result = super
  result["text"] = text.to_s
  result
end