Class: RubyLint::Docstring::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-lint/docstring/mapping.rb

Overview

Mapping is a small data container for storing docstring tags separately and optionally by their names (e.g. for parameter tags).

Constant Summary

TAG_METHODS =

Hash containing the known tag classes and their callback methods.

Returns:

  • (Hash)
{
  ParamTag  => :on_param_tag,
  ReturnTag => :on_return_tag
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags = []) ⇒ Mapping

Returns a new instance of Mapping

Parameters:

  • tags (Array) (defaults to: [])


30
31
32
33
34
35
36
# File 'lib/ruby-lint/docstring/mapping.rb', line 30

def initialize(tags = [])
  @param_tags = {}

  tags.each do |tag|
    send(TAG_METHODS[tag.class], tag)
  end
end

Instance Attribute Details

#param_tagsHash (readonly)

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby-lint/docstring/mapping.rb', line 14

class Mapping
  attr_reader :param_tags, :return_tag

  ##
  # Hash containing the known tag classes and their callback methods.
  #
  # @return [Hash]
  #
  TAG_METHODS = {
    ParamTag  => :on_param_tag,
    ReturnTag => :on_return_tag
  }

  ##
  # @param [Array] tags
  #
  def initialize(tags = [])
    @param_tags = {}

    tags.each do |tag|
      send(TAG_METHODS[tag.class], tag)
    end
  end

  private

  ##
  # @param [RubyLint::Docstring::ParamTag] tag
  #
  def on_param_tag(tag)
    @param_tags[tag.name] = tag
  end

  ##
  # @param [RubyLint::Docstring::ReturnTag] tag
  #
  def on_return_tag(tag)
    @return_tag = tag
  end
end

#return_tagRubyLint::Docstring::ReturnTag (readonly)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby-lint/docstring/mapping.rb', line 14

class Mapping
  attr_reader :param_tags, :return_tag

  ##
  # Hash containing the known tag classes and their callback methods.
  #
  # @return [Hash]
  #
  TAG_METHODS = {
    ParamTag  => :on_param_tag,
    ReturnTag => :on_return_tag
  }

  ##
  # @param [Array] tags
  #
  def initialize(tags = [])
    @param_tags = {}

    tags.each do |tag|
      send(TAG_METHODS[tag.class], tag)
    end
  end

  private

  ##
  # @param [RubyLint::Docstring::ParamTag] tag
  #
  def on_param_tag(tag)
    @param_tags[tag.name] = tag
  end

  ##
  # @param [RubyLint::Docstring::ReturnTag] tag
  #
  def on_return_tag(tag)
    @return_tag = tag
  end
end

Instance Method Details

#on_param_tag(tag) ⇒ Object (private)

Parameters:



43
44
45
# File 'lib/ruby-lint/docstring/mapping.rb', line 43

def on_param_tag(tag)
  @param_tags[tag.name] = tag
end

#on_return_tag(tag) ⇒ Object (private)

Parameters:



50
51
52
# File 'lib/ruby-lint/docstring/mapping.rb', line 50

def on_return_tag(tag)
  @return_tag = tag
end