Module: CabbageDoc::Parser

Included in:
Action, Controller, Example, Parameter
Defined in:
lib/cabbage_doc/parser.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/cabbage_doc/parser.rb', line 4

def included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#parse(text, tag = TAG) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/cabbage_doc/parser.rb', line 16

def parse(text, tag = TAG)
  raise NotImplementedError
end

#parse_option(text) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cabbage_doc/parser.rb', line 20

def parse_option(text)
  m = text.match(/^\((.*?)\)$/)
  return {} unless m

  {}.tap do |hash|
    m[1].split(/,/).map(&:strip).each do |o|
      k, v = o.split(':').map(&:strip)
      next unless k && v

      v = v.split('|').map(&:strip)
      v = v.first if v.size == 1

      hash[k.to_sym] = v
    end
  end
end

#parse_templates(text) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/cabbage_doc/parser.rb', line 37

def parse_templates(text)
  templates = []

  text.scan(/(\{(.*?)\})/) do
    templates << { text: $1, values: $2.split(/,/).map(&:strip) }
  end

  templates
end