Sha256: 020b61c72d237f40f091982b82f289d5093de05470b6d56336abd051ec7b2264

Contents?: true

Size: 860 Bytes

Versions: 4

Compression:

Stored size: 860 Bytes

Contents

require 'parser/factory'
require 'parallel'

module Rubrowser
  module Parser
    class Directory
      attr_reader :directory

      def initialize(directory)
        @directory = directory
        @parsers = []
        read
      end

      def parse
        self.parsers = Parallel.map(parsers){ |parser| parser.parse }
        self
      end

      def definitions
        parsers.map(&:definitions).map(&:to_a).reduce(:+) || []
      end

      def occurences
        parsers.map(&:occurences).map(&:to_a).reduce(:+) || []
      end

      def count
        parsers.map(&:count).reduce(:+)
      end

      private

      attr_accessor :parsers

      def read
        files = Dir.glob(::File.join(directory, '**', '*.rb'))
        self.parsers = Parallel.map(files) do |file|
          Factory.build(file)
        end.compact
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubrowser-0.1.3 lib/parser/directory.rb
rubrowser-0.1.2 lib/parser/directory.rb
rubrowser-0.1.1 lib/parser/directory.rb
rubrowser-0.1.0 lib/parser/directory.rb