Class: ParseDir
- Includes:
- CssParser, Format, HtmlParser
- Defined in:
- lib/parse_dir.rb
Constant Summary
Constants included from Format
Constants inherited from LoadDir
LoadDir::CSS_PATH, LoadDir::HTML_PATH
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
-
#html ⇒ Object
Returns the value of attribute html.
Attributes inherited from LoadDir
Class Method Summary collapse
Instance Method Summary collapse
- #css?(file) ⇒ Boolean
- #empty ⇒ Object
- #found(hash = self.parse_css) ⇒ Object
- #html?(file) ⇒ Boolean
-
#initialize(args) ⇒ ParseDir
constructor
A new instance of ParseDir.
- #parse_css ⇒ Object
- #segregate ⇒ Object
- #success? ⇒ Boolean
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
#css ⇒ Object
Returns the value of attribute css.
11 12 13 |
# File 'lib/parse_dir.rb', line 11 def css @css end |
#html ⇒ Object
Returns the value of attribute html.
11 12 13 |
# File 'lib/parse_dir.rb', line 11 def html @html end |
Class Method Details
.success_message ⇒ Object
86 87 88 89 90 |
# File 'lib/parse_dir.rb', line 86 def self. 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
21 22 23 |
# File 'lib/parse_dir.rb', line 21 def css?(file) true if /\.css\S*\z/.match(file) end |
#empty ⇒ Object
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
25 26 27 |
# File 'lib/parse_dir.rb', line 25 def html?(file) true if/\.html\S*\z/.match(file) end |
#parse_css ⇒ Object
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 |
#segregate ⇒ Object
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 |