Class: MarkdownComposer::Source
- Inherits:
-
Object
- Object
- MarkdownComposer::Source
- Defined in:
- lib/markdown_composer/source.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#markdown ⇒ Object
readonly
Returns the value of attribute markdown.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#preferred_format ⇒ Object
readonly
Returns the value of attribute preferred_format.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
- #format ⇒ Object
- #html_present? ⇒ Boolean
-
#initialize(key:, type: "explicit", title: nil, markdown: nil, html: nil, preferred_format: :markdown, metadata: {}) ⇒ Source
constructor
A new instance of Source.
- #markdown_present? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(key:, type: "explicit", title: nil, markdown: nil, html: nil, preferred_format: :markdown, metadata: {}) ⇒ Source
Returns a new instance of Source.
15 16 17 18 19 20 21 22 23 |
# File 'lib/markdown_composer/source.rb', line 15 def initialize(key:, type: "explicit", title: nil, markdown: nil, html: nil, preferred_format: :markdown, metadata: {}) @key = key.to_s @type = type.to_s @title = title @markdown = markdown @html = html @preferred_format = preferred_format.to_sym @metadata = || {} end |
Instance Attribute Details
#html ⇒ Object (readonly)
Returns the value of attribute html.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def html @html end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def key @key end |
#markdown ⇒ Object (readonly)
Returns the value of attribute markdown.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def markdown @markdown end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def @metadata end |
#preferred_format ⇒ Object (readonly)
Returns the value of attribute preferred_format.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def preferred_format @preferred_format end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/markdown_composer/source.rb', line 5 def type @type end |
Class Method Details
.build(value) ⇒ Object
7 8 9 |
# File 'lib/markdown_composer/source.rb', line 7 def self.build(value) value.is_a?(Source) ? value : new(**symbolize(value)) end |
.symbolize(value) ⇒ Object
11 12 13 |
# File 'lib/markdown_composer/source.rb', line 11 def self.symbolize(value) value.to_h.transform_keys(&:to_sym) end |
Instance Method Details
#content ⇒ Object
33 34 35 |
# File 'lib/markdown_composer/source.rb', line 33 def content format == :html ? html.to_s : markdown.to_s end |
#format ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/markdown_composer/source.rb', line 25 def format return :html if preferred_format == :html && html_present? return :markdown if markdown_present? return :html if html_present? preferred_format end |
#html_present? ⇒ Boolean
41 42 43 |
# File 'lib/markdown_composer/source.rb', line 41 def html_present? !html.to_s.empty? end |
#markdown_present? ⇒ Boolean
37 38 39 |
# File 'lib/markdown_composer/source.rb', line 37 def markdown_present? !markdown.to_s.empty? end |
#to_h ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/markdown_composer/source.rb', line 45 def to_h { key: key, type: type, title: title, markdown: markdown, html: html, preferred_format: preferred_format, metadata: }.compact end |