module Format
PATH = Dir.pwd
BASE = File.expand_path('../../base.css', __FILE__)
CSS_PATH = PATH + "/old_style/index.css"
def new_or_open_index
unless File.directory?(PATH + "/old_style")
Dir.mkdir(PATH + "/old_style")
end
File.open(PATH + "/old_style/index.html", 'w+')
end
def base_css_count
File.readlines(BASE).count == File.readlines(CSS_PATH).count
end
def create_css_file?
unless File.exists?(CSS_PATH) && base_css_count
write_css
true
else
false
end
end
def write_css
file = File.new(CSS_PATH, 'w+')
File.readlines(BASE).each do |line|
file.write line
end
file.close
end
def write_index
file = new_or_open_index
create_css_file?
file.write "
"
file.write ""
file.write ""
file.write ""
file.write "
"
file.write "
#{self.directories.sort_by{|x| x.downcase}}
"
file.write ""
file.write "
#{self.css.count} css files compared to
#{self.html.count} html files
"
file.write "
"
file.write "
"
file.write "
Css
"
self.css.each do |css, path|
file.write "
#{css}"
end
file.write "
"
file.write "
"
file.write "
Html
"
self.html.each do |html, path|
file.write "
#{html}"
end
file.write "
"
file.write "
"
file.write "
"
file.write "
"
file.write "
Good"
file.write " #{self.good_percent}"
file.write ""
file.write "
"
self.found.sort_by{|x| x.first.downcase}.each do |style, desc|
file.write "
#{style} {#{desc}}"
end
file.write ""
file.write "
"
file.write "
"
file.write "
"
file.write "
Bad
"
file.write " #{self.bad_percent}"
file.write ""
file.write "
"
self.empty.sort_by{|x| x.first.downcase}.each do |style, desc|
file.write "
#{style} {#{desc}}"
end
file.write ""
file.write "
"
file.write "
"
file.write ""
file.write ""
file.close
true
end
def good_percent
x = self.found.keys.count/(self.found.keys.count + self.empty.keys.count).to_f
y = (x * 100).to_s
z = /(.{5}|.{3}.|.{2})/.match(y)
z.to_s + "%"
end
def bad_percent
x = self.empty.keys.count/(self.found.keys.count + self.empty.keys.count).to_f
y = (x * 100).to_s
z = /(.{5}|.{3}.|.{2})/.match(y)
z.to_s + "%"
end
end