Sha256: f29956f1eeda5bac36e671cbe9d2e4d3ff6736430ae4d4efd4ac50c200e134aa

Contents?: true

Size: 1009 Bytes

Versions: 7

Compression:

Stored size: 1009 Bytes

Contents

module Faml
  class FilterParser
    def initialize(indent_tracker)
      @ast = nil
      @indent_level = nil
      @indent_tracker = indent_tracker
    end

    def enabled?
      !!@ast
    end

    def start(name)
      @ast = Ast::Filter.new
      @ast.name = name
    end

    def append(line)
      indent, text = @indent_tracker.split(line)
      if text.empty?
        @ast.texts << ''
        return
      end
      indent_level = indent.size

      if @indent_level
        if indent_level < @indent_level
          # Finish filter
          @indent_level = nil
          ast = @ast
          @ast = nil
          return ast
        end
      else
        if indent_level > @indent_tracker.current_level
          # Start filter
          @indent_level = indent_level
        else
          # Empty filter
          @ast = nil
          return nil
        end
      end

      text = line[@indent_level .. -1]
      @ast.texts << text
      nil
    end

    def finish
      @ast
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
faml-0.2.6 lib/faml/filter_parser.rb
faml-0.2.5 lib/faml/filter_parser.rb
faml-0.2.4 lib/faml/filter_parser.rb
faml-0.2.3 lib/faml/filter_parser.rb
faml-0.2.2 lib/faml/filter_parser.rb
faml-0.2.1 lib/faml/filter_parser.rb
faml-0.2.0 lib/faml/filter_parser.rb