Sha256: 1f356b76025cf0ae69133248e6d4d09b8d879653b04fda91a6d36fc83ecc5429

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 Bytes

Contents

module LOCat

  #
  class Matcher
    include Enumerable

    #
    def initialize(*config_files)
      @rules = []

      if config_files.empty?
        default
      end

      config_files.each do |f|
        instance_eval(File.read(f))
      end
    end

    #
    attr :rules

    #
    def match(files, &block)
      @rules << [files, block]
    end

    #
    def each(&block)
      @rules.each(&block)
    end

    #
    def size
      @rules.size
    end

  private

    # Default configuration if none is supplied by the project.
    def default
      match 'lib/**.rb' do |file, line|
        case line
        when /^\s*#/
          'Comment'
        when /^\s*$/
          'Blank'
        else
          'Code'
        end
      end
      match 'test/**.rb' do |file, line|
        case line
        when /^\s*#/
          'Comment'
        when /^\s*$/
          'Blank'
        else
          'Test'
        end
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locat-0.2.4 lib/locat/matcher.rb
locat-0.2.3 lib/locat/matcher.rb
locat-0.2.0 lib/locat/matcher.rb