Sha256: 1d31f446832af94f886fac2d09e6265c5e1e581da9dbcc828566bb483618e0e8

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

module Trufflepig
  class Search
    attr_accessor :results, :path

    EXCLUDED_FILENAMES = /#{%w{
      jquery prototype yui dojo extjs raphael zepto enyo ember modernizr
      bootstrap foundation
    }.join('|')}/

    def initialize(path)
      @results = []
      @path = path
    end

    def perform
      raise Errno::ENOENT unless File.exists? path

      if File.directory?(path)
        Dir.chdir path
        files = {
          :html => Dir.glob(File.join("**", "*.html")),
          :js => Dir.glob(File.join("**", "*.js")),
          :css => Dir.glob(File.join("**", "*.css"))
        }
        files.each do |type, paths|
          paths.each  do |path|
            next if File.directory?(path)
            scan path unless path.split('/').last.match EXCLUDED_FILENAMES
          end
        end
      else
        scan path
      end
    end

    def scan(file_path)
      return unless File.exists? file_path
      content = File.open(file_path, "rb").read

      features.each do |feature|
        next unless feature["detection_pattern"]
        results << feature if content.match(/#{feature["detection_pattern"]}/)
      end
    end

    private

    def features
      @features ||= FeatureList.load
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trufflepig-0.2.13 lib/trufflepig/search.rb
trufflepig-0.2.12 lib/trufflepig/search.rb
trufflepig-0.2.11 lib/trufflepig/search.rb