Class: Trufflepig::Search
- Inherits:
-
Object
- Object
- Trufflepig::Search
- Defined in:
- lib/trufflepig/search.rb
Constant Summary collapse
- EXCLUDED_FILENAMES =
/#{%w{ jquery prototype yui dojo extjs raphael zepto enyo ember modernizr bootstrap foundation }.join('|')}/
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(path) ⇒ Search
constructor
A new instance of Search.
- #perform ⇒ Object
- #scan(file_path) ⇒ Object
Constructor Details
#initialize(path) ⇒ Search
Returns a new instance of Search.
10 11 12 13 |
# File 'lib/trufflepig/search.rb', line 10 def initialize(path) @results = [] @path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/trufflepig/search.rb', line 3 def path @path end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/trufflepig/search.rb', line 3 def results @results end |
Instance Method Details
#perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trufflepig/search.rb', line 15 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 |
#scan(file_path) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/trufflepig/search.rb', line 36 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 |