Sha256: ce17d4dd03b398b13502d321d297aa5d7dc4da00259b0e1b063b4c050bc2f1cd

Contents?: true

Size: 1.79 KB

Versions: 9

Compression:

Stored size: 1.79 KB

Contents

module Inch
  module Language
    module Nodejs
      module Provider
        module JSDoc
          class Docstring < Ruby::Provider::YARD::Docstring
            # Removes the comment markers // /* */ from the docstring.
            #
            #   Docstring.new("// test").without_comment_markers
            #   # => "test"
            #
            # @return [String]
            def without_comment_markers
              @text.lines.map do |line|
                line.strip.gsub(/^(\s*(\/\*+|\/\/|\*+\/|\*)+\s?)/m, '')
              end.join("\n").strip
            end

            def describes_internal_api?
              tag?(:api, :private) || super
            end

            def describes_parameter?(name)
              return false if name.nil?
              parameter = parameter_notations(name)
              tag?(:param, /#{parameter}\s+\S+/)
            end

            def mentions_parameter?(name)
              return false if name.nil?
              parameter = parameter_notations(name)
              tag?(:param, /#{parameter}/) || super
            end

            def mentions_return?
              tag?(:return) || super
            end

            def describes_return?
              type_notation = /(\{[^\}]+\}|\[[^\]]+\])/
              tag?(:return, /#{type_notation}*(\s\w+)/) || super
            end

            def visibility
              %w(public protected private).detect do |v|
                tag?(v)
              end || 'public'
            end

            def tag?(tagname, regex = nil)
              if without_comment_markers =~ /^\s*\@#{tagname}([^\n]*)$/m
                if regex.nil?
                  true
                else
                  $1 =~ /#{regex}/
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
inch-0.5.5 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.4 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.3 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.2 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.1 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.0 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.0.rc11 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.0.rc10 lib/inch/language/nodejs/provider/jsdoc/docstring.rb
inch-0.5.0.rc9 lib/inch/language/nodejs/provider/jsdoc/docstring.rb