class ParseDir

Attributes

css[RW]
html[RW]

Public Class Methods

new(args) click to toggle source
Calls superclass method LoadDir::new
# File lib/parse_dir.rb, line 13
def initialize(args)
  super(args)
  @css = {}
  @html = {}
  self.segregate
  self.parse_css
end
success_message() click to toggle source
# File lib/parse_dir.rb, line 86
def self.success_message
 puts Time.now.strftime("%B %d %Y %r")
 puts "Your report was generated at #{Dir.pwd}/old_style/index/html"
 true
end

Public Instance Methods

css?(file) click to toggle source
# File lib/parse_dir.rb, line 21
def css?(file)
  true if /\.css\S*\z/.match(file)
end
empty() click to toggle source
# File lib/parse_dir.rb, line 69
def empty
  hash = {}
  all = self.parse_css.inject([]) {|a, k| a << k}
  found_css = self.found.inject([]) {|a, k| a << k}
  empty_css = all - found_css
  empty_css.each {|arr| hash[arr.first] = arr.last}
  hash
end
found(hash=self.parse_css) click to toggle source
# File lib/parse_dir.rb, line 53
def found hash=self.parse_css 
  tmp = {}
  self.html.each do |file|
    hash.each do |sel, des|
      if sel.match("#")
        tmp[sel] = des if id_exists?(sel, file.last) == true
      elsif sel.match(/^\./)
        tmp[sel] = des if class_exists?(sel, file.last) == true
      elsif sel.match(/^\w/)
        tmp[sel] = des if  parent_exists?(sel, file.last) == true
      end
    end
  end
  tmp
end
html?(file) click to toggle source
# File lib/parse_dir.rb, line 25
def html?(file)
  true if/\.html\S*\z/.match(file)
end
parse_css() click to toggle source
# File lib/parse_dir.rb, line 39
def parse_css
  hash = {}
  self.css.each do |file, path|
    parser = CssParser::Parser.new
    parser.load_file!(file, path, :all)
    parser.each_selector(:all) do |selector, dec, spec|
      unless /(^\/|\$|@|\d|:hover)/.match(selector)
        hash[selector] = dec
      end
    end
  end
  hash
end
segregate() click to toggle source
# File lib/parse_dir.rb, line 29
def segregate
  self.files.each do |file, path|
    if self.css?(file)
      self.css[file] = path
    elsif self.html?(file)
      self.html[file] = path
    end
  end
end
success?() click to toggle source
# File lib/parse_dir.rb, line 78
def success?
  if self.write_index
   ParseDir.success_message
  else
   ParseDir.failure_message
  end
end