Sha256: b957a77914ae8796bdbcf1cd5321a33c99e9ce79c97824cee5c68c440b73a7fa

Contents?: true

Size: 893 Bytes

Versions: 7

Compression:

Stored size: 893 Bytes

Contents

module CabbageDoc
  module Parser
    class << self
      def included(base)
        base.extend(ClassMethods)
      end
    end

    module ClassMethods
      def parse(text)
        instance = new
        instance if instance.parse(text)
      end
    end

    def parse(text)
      raise NotImplementedError
    end

    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

    def parse_templates(text)
      templates = []

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

      templates
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cabbage_doc-0.0.7 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.6 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.5 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.4 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.3 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.2 lib/cabbage_doc/parser.rb
cabbage_doc-0.0.1 lib/cabbage_doc/parser.rb