Class: SleepingKingStudios::Docs::Data::Metadata

Inherits:
Base
  • Object
show all
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.

See Also:

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SleepingKingStudios::Docs::Data::Base

Instance Method Details

#abstractString?

Returns the @abstract tag, if any, defined for the module.

Returns:

  • (String)

    the contents of the @abstract tag, or an empty string if the tag does not have contents.

  • (nil)

    if there is no @abstract tag defined.



49
50
51
52
53
54
55
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 49

def abstract
  @abstract ||=
    native
    .tags
    .find { |tag| tag.tag_name == 'abstract' }
    &.text
end

#apiString?

Returns the @api tag, if any, defined for the module.

Returns:

  • (String)

    the contents of the @api tag.

  • (nil)

    if there is no @api tag defined.



61
62
63
64
65
66
67
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 61

def api
  @api ||=
    native
    .tags
    .find { |tag| tag.tag_name == 'api' }
    &.text
end

#as_jsonHash{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.

Returns:

  • (Hash{String => Object})

    the representation of the metadata.



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

#authorsArray<String>

Collects the @author tags defined for the module.

Returns:

  • (Array<String>)

    the collected authors.



94
95
96
97
98
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 94

def authors
  @authors ||=
    select_tags('author') { |tag| !tag.text.empty? }
    .map(&:text)
end

#deprecatedString?

Returns the @deprecated tag, if any, defined for the module.

Returns:

  • (String)

    the contents of the @deprecated tag, or an empty string if the tag does not have contents.

  • (nil)

    if there is no @deprecated tag defined.



105
106
107
108
109
110
111
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 105

def deprecated
  @deprecated ||=
    native
    .tags
    .find { |tag| tag.tag_name == 'deprecated' }
    &.text
end

#examplesArray<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.

Returns:

  • (Array<Hash{String => String}>)

    the collected examples.



121
122
123
124
125
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 121

def examples
  @examples ||=
    select_tags('example')
    .map { |tag| { 'name' => tag.name, 'text' => tag.text } }
end

#notesArray<String>

Collects the @note tags defined for the module.

Returns:

  • (Array<String>)

    the collected notes.



130
131
132
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 130

def notes
  @notes ||= select_tags('note').map(&:text)
end

#seeArray<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.

Returns:

  • (Array<Hash{String => String}>)


141
142
143
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 141

def see
  @see ||= select_tags('see').map { |tag| format_see_tag(tag) }
end

#sinceArray<String>

Collects the @since tags defined for the module.

Returns:

  • (Array<String>)

    the collected @since tags.



148
149
150
151
152
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 148

def since
  @since ||=
    select_tags('since') { |tag| !tag.text.empty? }
    .map(&:text)
end

#todosArray<String>

Collects the @todo tags defined for the module.

Returns:

  • (Array<String>)

    the collected todos.



157
158
159
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 157

def todos
  @todos ||= select_tags('todo').map(&:text)
end

#versionsArray<String>

Collects the @version tags defined for the module.

Returns:

  • (Array<String>)

    the collected @version tags.



164
165
166
167
168
# File 'lib/sleeping_king_studios/docs/data/metadata.rb', line 164

def versions
  @versions ||=
    select_tags('version') { |tag| !tag.text.empty? }
    .map(&:text)
end