Created
June 19, 2017 11:03
-
-
Save sftblw/52b7ce34888b78540597c2c931413934 to your computer and use it in GitHub Desktop.
.java 파일만 추출하는 루비 프로그램
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 필요에 의해 스크립트 짜는 걸 nodejs 대신 루비로 하기로 마음먹고 짠 코드 | |
# .java 를 적당한 이름을 붙여 모읍니다. | |
require 'fileutils' | |
Dir.glob('**/*.java') do |filepath| | |
filename = filepath.split(/\//)[-1] | |
question_number = nil | |
student_id = nil | |
filepath.split(/\//).reverse_each do |chunk| | |
regex_result = nil | |
# 학번 | |
if (regex_result = chunk.match(/([0-9]{10})/)) != nil and student_id == nil then student_id = regex_result[0] end | |
# 문제 번호 | |
if (regex_result = chunk.match(/(1|[Rr]adio|[Cc]heck|[Cc]ombo)/)) != nil and question_number == nil then question_number = 1 end | |
if (regex_result = chunk.match(/(2|[Cc]lock|[Ww]atch|[Cc]alc|[Ww]hite|[Bb]oard)/)) != nil and question_number == nil then question_number = 2 end | |
if (regex_result = chunk.match(/(3|[Pp]hilo|[Pp]oly|[Rr]ect|[Tt]rian|[Ss]tack|[Pp]rodu|[Cc]onsum)/)) != nil and question_number == nil then question_number = 3 end | |
end | |
if question_number == nil then question_number = 'unknown' end | |
filename = student_id + '_' + question_number.to_s + '___' + filename | |
puts filename + "\t\t<=\t\t" + filepath | |
if not File.exist?('../rendered') then FileUtils.mkdir('../rendered') end | |
FileUtils.cp( filepath, File.join('../rendered', filename).to_s ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment