Class: ParseDir

Inherits:
LoadDir show all
Includes:
CssParser, Format, HtmlParser
Defined in:
lib/parse_dir.rb

Constant Summary

Constants included from Format

Format::BASE, Format::PATH

Constants inherited from LoadDir

LoadDir::CSS_PATH, LoadDir::HTML_PATH

Instance Attribute Summary collapse

Attributes inherited from LoadDir

#directories, #files

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HtmlParser

#class_exists?, #id_exists?, #parent_exists?, #read_html, #remove_extras

Methods included from Format

#bad_percent, #create_css_file?, #css_path, #good_percent, #new_or_open_index, #write_css, #write_index

Methods inherited from LoadDir

#css_files, #dir_iteration, #html_files

Constructor Details

#initialize(args) ⇒ ParseDir

Returns a new instance of ParseDir.



13
14
15
16
17
18
19
# File 'lib/parse_dir.rb', line 13

def initialize(args)
  super(args)
  @css = {}
  @html = {}
  self.segregate
  self.parse_css
end

Instance Attribute Details

#cssObject

Returns the value of attribute css.



11
12
13
# File 'lib/parse_dir.rb', line 11

def css
  @css
end

#htmlObject

Returns the value of attribute html.



11
12
13
# File 'lib/parse_dir.rb', line 11

def html
  @html
end

Class Method Details

.success_messageObject



86
87
88
89
90
# 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

Instance Method Details

#css?(file) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/parse_dir.rb', line 21

def css?(file)
  true if /\.css\S*\z/.match(file)
end

#emptyObject



69
70
71
72
73
74
75
76
# 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) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/parse_dir.rb', line 25

def html?(file)
  true if/\.html\S*\z/.match(file)
end

#parse_cssObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

#segregateObject



29
30
31
32
33
34
35
36
37
# 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?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/parse_dir.rb', line 78

def success?
  if self.write_index
   ParseDir.success_message
  else
   ParseDir.failure_message
  end
end