Class: SleepingKingStudios::Docs::Data::Metadata
- Defined in:
- lib/sleeping_king_studios/docs/data/metadata.rb
Overview
Object representing the metadata tags for a Ruby module.
Each module can have the following metadata tags:
- @example
- @note
- @see
- @todo
Other tags are not currently supported.
Instance Method Summary collapse
-
#abstract ⇒ String?
Returns the @abstract tag, if any, defined for the module.
-
#api ⇒ String?
Returns the @api tag, if any, defined for the module.
-
#as_json ⇒ Hash{String => Object}
Generates a JSON-compatible representation of the metadata.
-
#authors ⇒ Array<String>
Collects the @author tags defined for the module.
-
#deprecated ⇒ String?
Returns the @deprecated tag, if any, defined for the module.
-
#examples ⇒ Array<Hash{String => String}>
Collects the @example tags defined for the module.
-
#notes ⇒ Array<String>
Collects the @note tags defined for the module.
-
#see ⇒ Array<Hash{String => String}>
Collects the @see tags defined the for the module.
-
#since ⇒ Array<String>
Collects the @since tags defined for the module.
-
#todos ⇒ Array<String>
Collects the @todo tags defined for the module.
-
#versions ⇒ Array<String>
Collects the @version tags defined for the module.
Methods inherited from Base
Constructor Details
This class inherits a constructor from SleepingKingStudios::Docs::Data::Base
Instance Method Details
#abstract ⇒ String?
Returns the @abstract tag, if any, defined for the module.
49 50 51 52 53 54 55 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 49 def abstract @abstract ||= native . .find { |tag| tag.tag_name == 'abstract' } &.text end |
#api ⇒ String?
Returns the @api tag, if any, defined for the module.
61 62 63 64 65 66 67 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 61 def api @api ||= native . .find { |tag| tag.tag_name == 'api' } &.text end |
#as_json ⇒ Hash{String => Object}
Generates a JSON-compatible representation of the metadata.
Returns a Hash with zero or more of the following keys:
- 'examples': An Array of Hashes with keys 'name' and 'text' and String values.
- 'notes': An Array of Strings.
- 'see': An Array of Hashes with String values.
- 'todo': An Array of Strings.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 80 def as_json METADATA_PROPERTIES .reduce({}) do |memo, property_name| value = send(property_name) next memo if emptyable?(property_name) ? value.nil? : empty?(value) memo.update(property_name.to_s => value) end end |
#authors ⇒ Array<String>
Collects the @author tags defined for the module.
94 95 96 97 98 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 94 def @authors ||= ('author') { |tag| !tag.text.empty? } .map(&:text) end |
#deprecated ⇒ String?
Returns the @deprecated tag, if any, defined for the module.
105 106 107 108 109 110 111 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 105 def deprecated @deprecated ||= native . .find { |tag| tag.tag_name == 'deprecated' } &.text end |
#examples ⇒ Array<Hash{String => String}>
Collects the @example tags defined for the module.
Each @example tag is represented as a Hash with the following keys:
- 'name': The displayed name of the example. May be an empty String.
- 'text': The text for the example.
121 122 123 124 125 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 121 def examples @examples ||= ('example') .map { |tag| { 'name' => tag.name, 'text' => tag.text } } end |
#notes ⇒ Array<String>
Collects the @note tags defined for the module.
130 131 132 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 130 def notes @notes ||= ('note').map(&:text) end |
#see ⇒ Array<Hash{String => String}>
Collects the @see tags defined the for the module.
Each @see tag is represented as a Hash with String keys and values, and has at a minimum the 'text' key. See the SeeTag#as_json method for details.
141 142 143 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 141 def see @see ||= ('see').map { |tag| format_see_tag(tag) } end |
#since ⇒ Array<String>
Collects the @since tags defined for the module.
148 149 150 151 152 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 148 def since @since ||= ('since') { |tag| !tag.text.empty? } .map(&:text) end |
#todos ⇒ Array<String>
Collects the @todo tags defined for the module.
157 158 159 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 157 def todos @todos ||= ('todo').map(&:text) end |
#versions ⇒ Array<String>
Collects the @version tags defined for the module.
164 165 166 167 168 |
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 164 def versions @versions ||= ('version') { |tag| !tag.text.empty? } .map(&:text) end |