module CabbageDoc::Parser
Public Class Methods
included(base)
click to toggle source
# File lib/cabbage_doc/parser.rb, line 4 def included(base) base.extend(ClassMethods) end
Public Instance Methods
parse(text, tag = TAG)
click to toggle source
# File lib/cabbage_doc/parser.rb, line 16 def parse(text, tag = TAG) raise NotImplementedError end
parse_option(text)
click to toggle source
# 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, tag = TAG)
click to toggle source
# File lib/cabbage_doc/parser.rb, line 37 def parse_templates(text, tag = TAG) templates = {} mappings = Configuration.instance.templates.fetch(tag.to_sym, {}) text.scan(/(\{(.*?)\})/) do text = $1.dup values = Array(mappings.fetch(text, $2.split(/,/).map(&:strip)).dup) templates[text] = values end templates end