Class: Yardstick::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/yardstick/document.rb

Overview

Wraps a yard docstring to make a nicer interface

Defined Under Namespace

Classes: NullTag

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docstring) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes Document object with docstring

Parameters:

  • (Yard::Docstring)


61
62
63
# File 'lib/yardstick/document.rb', line 61

def initialize(docstring)
  @docstring = docstring
end

Class Attribute Details

.registered_rulesArray<Class> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Shows currently registered rules

Returns:

  • (Array<Class>)


14
15
16
# File 'lib/yardstick/document.rb', line 14

def registered_rules
  @registered_rules
end

Instance Attribute Details

#docstringYARD::Docstring (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return document yard docstring

Returns:

  • (YARD::Docstring)


52
53
54
# File 'lib/yardstick/document.rb', line 52

def docstring
  @docstring
end

Class Method Details

.measure(document, config) ⇒ MeasurementSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Measures docstring against enabled rules

Parameters:

  • document (Yardstring::Document)

    document that will be measured

  • config (Yardstick::Config)

    a configuration

Returns:



39
40
41
42
43
44
45
# File 'lib/yardstick/document.rb', line 39

def self.measure(document, config)
  MeasurementSet.new(
    registered_rules.map do |rule_class|
      Measurement.new(rule_class.coerce(document, config))
    end
  )
end

.register_rule(rule_class) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register rule with document

Parameters:

  • rule_class (Class)

    subclass of Yardstick::Rule

Returns:

  • (undefined)


25
26
27
# File 'lib/yardstick/document.rb', line 25

def self.register_rule(rule_class)
  registered_rules << rule_class
end

Instance Method Details

#api?(types) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the method API type matches

Parameters:

  • types (Array<String>)

    a collection of API types

Returns:

  • (Boolean)

    true if the API type matches



133
134
135
# File 'lib/yardstick/document.rb', line 133

def api?(types)
  types.include?(tag_text('api'))
end

#filePathname

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The filename for the code

Returns:

  • (Pathname)

    the filename



143
144
145
# File 'lib/yardstick/document.rb', line 143

def file
  Pathname(object.file)
end

#has_tag?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Tests if document has a tag

Parameters:

  • name (String)

    the name of the tag

Returns:

  • (Boolean)

    true if tag exists



84
85
86
# File 'lib/yardstick/document.rb', line 84

def has_tag?(name) # rubocop:disable PredicateName
  @docstring.has_tag?(name)
end

#lineInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The line number for the code

Returns:

  • (Integer)

    the line number



153
154
155
# File 'lib/yardstick/document.rb', line 153

def line
  object.line
end

#pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The class and method name for the code

Returns:

  • (String)

    the class and method name



163
164
165
# File 'lib/yardstick/document.rb', line 163

def path
  object.path
end

#summary_textString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The raw text for the summary

Returns:

  • (String)

    the summary text



71
72
73
# File 'lib/yardstick/document.rb', line 71

def summary_text
  @docstring.split(/\r?\n\r?\n/).first.to_s
end

#tag_text(tag_name) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The text for a specified tag

Parameters:

  • tag_name (String)

    the name of the tag

Returns:

  • (String, nil)

    the tag text if the tag exists



97
98
99
# File 'lib/yardstick/document.rb', line 97

def tag_text(tag_name)
  tag(tag_name).text
end

#tag_types(tag_name) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The types for a specified tag

Parameters:

  • tag_name (String)

    the name of the tag

Returns:

  • (Array<String>)

    a collection of tag types



110
111
112
# File 'lib/yardstick/document.rb', line 110

def tag_types(tag_name)
  tag(tag_name).types
end

#visibilitySymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The method visibility: public, protected or private

Returns:

  • (Symbol)

    the visibility of the method



120
121
122
# File 'lib/yardstick/document.rb', line 120

def visibility
  object.visibility
end