Class: DocDigger::LineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/doc-digger/line_parser.rb

Constant Summary collapse

PICKS =
{ java: /\A\s*\*/, erlang: /\A\s*%/, perl: /\A\s*#/ }
COMMANDS =
/\A@(doc(\_state)?|res(\_(param|response|state|bind))?|cmd\_(def|use))\Z/
PARAMETER_LOCATIONS =
/\Apath|query|header|form|body\Z/
RESPONSE_LOCATIONS =
/\Aheader|body\Z/

Instance Method Summary collapse

Constructor Details

#initialize(str, clazz) ⇒ LineParser

Returns a new instance of LineParser.



9
10
11
12
13
# File 'lib/doc-digger/line_parser.rb', line 9

def initialize(str, clazz)
  @clazz = clazz
  pick = PICKS[clazz]
  @str = pick.nil? ? str : str.gsub(pick, '')
end

Instance Method Details

#indentationObject



25
26
27
# File 'lib/doc-digger/line_parser.rb', line 25

def indentation
  @indentation ||= @str.match(/\A\s*/)[0].length
end

#parseObject



15
16
17
18
19
20
21
22
23
# File 'lib/doc-digger/line_parser.rb', line 15

def parse
  parts = @str.strip.split(/\s+/)
  command = parts[0].to_s.match(COMMANDS)
  if command.nil? || command[1].nil?
    { type: :joint, text: @str }
  else
    send(command[1], parts[1..-1], command)
  end
end