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

Inherits:
Base
  • Object
show all
Defined in:
lib/docbook/mirror/node.rb,
lib/docbook/mirror/node/text.rb

Overview

Nested classes for all node types

Constant Summary collapse

PM_TYPE =
"text"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: "") ⇒ Text

Returns a new instance of Text.



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

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

Instance Attribute Details

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.from_h(hash) ⇒ Object



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

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



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

def text_content
  text.to_s
end

#to_hObject



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

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