Class: Coradoc::AsciiDoc::Model::TextElement
- Inherits:
-
Base
- Object
- Lutaml::Model::Serializable
- Base
- Coradoc::AsciiDoc::Model::TextElement
- Defined in:
- lib/coradoc/asciidoc/model/text_element.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#hard_break? ⇒ Boolean
Semantic predicates over the line-break marker.
- #inline? ⇒ Boolean
- #soft_break? ⇒ Boolean
-
#text ⇒ String
Alias for text to work with ContentList.
-
#to_s ⇒ String
Get text content as string.
Methods inherited from Base
#block_level?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit
Class Method Details
.escape_keychars(string) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 43 def self.escape_keychars(string) subs = { '*' => '\*', '_' => '\_' } string .gsub(/((?<=\s)[*_]+)|[*_]+(?=\s)/) do |n| n.chars.map do |char| subs[char] end.join end end |
Instance Method Details
#hard_break? ⇒ Boolean
Semantic predicates over the line-break marker. Consumers (the transformer, the serializer) call these instead of comparing line_break against literal strings, so the wire format for hard breaks is owned by the model layer (SRP).
35 36 37 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 35 def hard_break? line_break == LineBreakMarker::HARD end |
#inline? ⇒ Boolean
17 18 19 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 17 def inline? true end |
#soft_break? ⇒ Boolean
39 40 41 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 39 def soft_break? line_break.to_s.empty? end |
#text ⇒ String
Alias for text to work with ContentList
82 83 84 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 82 def text to_s end |
#to_s ⇒ String
Get text content as string
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/coradoc/asciidoc/model/text_element.rb', line 57 def to_s case content when String content when Array content.map(&:to_s).join when Coradoc::AsciiDoc::Model::Base content.to_adoc when Lutaml::Model::Serializable if content.class.attributes.key?(:content) content.content.to_s else '' end when nil '' else content.is_a?(String) ? content.to_s : '' end end |