Class: Yard2steep::Comments

Inherits:
Object
  • Object
show all
Defined in:
lib/yard2steep/comments.rb

Constant Summary collapse

S_RE =
/[\s\t]*/
TYPE_WITH_PAREN_RE =
/
  \[
  (
    [^\]]
    *
  )
  \]
/x
COMMENT_RE =
/^
  \#
  #{S_RE}
  @(?:param|return)
  #{S_RE}
  #{TYPE_WITH_PAREN_RE}
/x
PARAM_RE =
/
  \#
  #{S_RE}
  @param
  #{S_RE}
  #{TYPE_WITH_PAREN_RE}
  #{S_RE}
  (\w+)
/x
RETURN_RE =
/
  \#
  #{S_RE}
  @return
  #{S_RE}
  #{TYPE_WITH_PAREN_RE}
/x

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Comments

Returns a new instance of Comments.

Parameters:

  • text (String)


39
40
41
# File 'lib/yard2steep/comments.rb', line 39

def initialize(text)
  @comments_map = extract(text)
end

Instance Method Details

#parse_from(m_loc) ⇒ Array(Hash { String => String }, String)

Parameters:

  • m_loc (Integer)

    represents location of method definition

Returns:

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


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yard2steep/comments.rb', line 45

def parse_from(m_loc)
  Util.assert! { m_loc >= 0 }
  reset_context!

  l = m_loc - 1
  while l >= 0
    comment = @comments_map[l]
    break unless comment  # nil when no more comment exist

    parse_comment!(comment)
    l -= 1
  end

  [@p_types, @r_type]
end