@@ -4,6 +4,9 @@ require 'httparty'
44require 'fileutils'
55
66CONTENT_DIR = "./content"
7+ FILE_NAME_OVERRIDES = {
8+ "excessiveclasscomplexity" => "weightedmethodcount" ,
9+ }
710
811categories = {
912 cleancode : "http://phpmd.org/rules/cleancode.txt" ,
@@ -15,11 +18,14 @@ categories = {
1518}
1619
1720FileUtils . rm_rf ( CONTENT_DIR )
21+ FileUtils . mkdir_p ( CONTENT_DIR )
1822
19- categories . each do |category , url |
20- category_path = "#{ CONTENT_DIR } /#{ category } /"
21- FileUtils . mkdir_p ( category_path )
23+ def file_name ( header )
24+ file_name = header . gsub ( " " , "_" ) . downcase
25+ FILE_NAME_OVERRIDES . fetch ( file_name , file_name )
26+ end
2227
28+ categories . each do |category , url |
2329 text = HTTParty . get ( url ) . body
2430
2531 matches = text . split ( /=+\n .*?\n =+/ , 2 ) . pop
@@ -34,7 +40,6 @@ categories.each do |category, url|
3440 body = body . split ( /This rule.*/ ) . shift
3541 body += "\n ```"
3642
37-
3843 array << body
3944 array << title
4045 end
@@ -45,8 +50,7 @@ categories.each do |category, url|
4550 sections . each_slice ( 2 ) do |( header , body ) |
4651 next if header == "Remark"
4752
48- file_name = header . gsub ( " " , "_" ) . downcase
49- File . open ( "#{ category_path } /#{ file_name } .txt" , "w" ) do |file |
53+ File . open ( "#{ CONTENT_DIR } /#{ file_name ( header ) } .txt" , "w" ) do |file |
5054 file . write ( body )
5155 end
5256 end
0 commit comments