# ½ºÅ©¸³Æ® ±â¹Ý Ŭ·¡½º # °¢ ½ºÅ©¸³Æ®º° ±ÔÄ¢ °ËÁõ¸¦ À§ÇÑ ÇÏÀ§ Ŭ·¡½ºµéÀº ÀÌ ±â¹Ý Ŭ·¡½º¿¡¼­ ÆÄ»ý class Script attr_accessor :name, :path, :checker def initialize(required, name, path) @required = required # Çʼö ½ºÅ©¸³Æ®Àΰ¡ @name = name # ½ºÅ©¸³Æ® À̸§ @path = path # µð·ºÅ丮 ±âÁØ ÆÄÀÏ °æ·Î @checker = nil @head_array = [] # Ä÷³ Çì´õ ¹®ÀÚ¿­ ¹è¿­ @head_hash = {} # Ä÷³ Çì´õ => Ä÷³ À妽º ÇØ½Ã @line_num = 0 # ÇöÀç ó¸® ÁßÀÎ Çà ¹øÈ£ @should_check_space = true end def check(dir) unless File.exist?(File.join(dir, path)) if @required puts "[ERROR] #{@name} : ÆÄÀÏÀ» ãÀ» ¼ö ¾øÀ½" set_error else puts "[WARNING] #{@name} : ÆÄÀÏÀ» ãÀ» ¼ö ¾øÀ½" end return end @line_num = 0 got_head_line = false IO.foreach(File.join(dir, path)) do |line| @line_num += 1 s = line.lstrip # ¼±Çà °ø¹é »èÁ¦ next if s[0..1] == '//' # ÁÖ¼® ¶óÀÎÀº °Ç³Ê¶Ú´Ù tokens = s.split("\t") # °¢ Ä÷³Àº ÅÇ("\t")À¸·Î ±¸ºÐ next unless tokens if @should_check_space # ÅÇ("\t")À¸·Î ºÐ¸®µÈ ÅäÅ« Áß °ø¹é ¹®ÀÚ(" ")°¡ Æ÷ÇÔµÈ °ÍÀÌ Àִ°¡ # ÅäÅ« Áß°£ÀÇ °ø¹é ¹®ÀÚ´Â ÆÄ¼­ ¿À·ù¸¦ À¯¹ßÇÑ´Ù col_num = Script.has_inner_space(tokens) if col_num >= 0 puts "[ERROR] #{@name} : À߸øµÈ °ø¹é ¹®ÀÚ (line #{@line_num} col #{col_num})" set_error next end end unless got_head_line @head_array = tokens # ÁÖ¼®ÀÌ ¾Æ´Ñ ù ¶óÀÎÀº Ä÷³ Çì´õ¿©¾ß ÇÑ´Ù col_index = -1 @head_array.each do |col_name| col_index += 1 if col_name.strip != '' and @head_hash.has_key?(col_name) puts "[ERROR] Duplicated column header '#{col_name}' (line #{@line_num})" set_error next end @head_hash[col_name] = col_index end got_head_line = true else # ÇöÀç Æ÷¸Ë¿¡¼­ ³»¿ë Ä÷³ ¼ö üũ ÀÇ¹Ì ¾øÀ½ # ½ºÅ©¸³Æ®º° »ó¼¼ °ËÁõ check_rule(tokens) end end end def check_rule(columns) # ¸ðµç ½ºÅ©¸³Æ®¿¡ °øÅëµÇ´Â »çÇ×ÀÌ ¾Æ´Ï¶ó¸é ÇÏÀ§ Ŭ·¡½º¿¡¼­ ±¸Çö end def col_index(col_name) @head_hash[col_name] end def Script.has_inner_space(tokens) col_num = 0 tokens.each do |token| col_num += 1 stripped = token.strip break if stripped.include?('//') # '//' ÀÌÈÄ·Î °Ë»çÇÏÁö ¾ÊÀ½ next unless stripped.include?(' ') return col_num end return -1 end end class ScriptChecker attr_accessor :dir, :item_table def initialize @script_array = [] @script_hash = {} @dir = '.' @item_table = {} end # °ËÁõ ´ë»ó ½ºÅ©¸³Æ® Ãß°¡ def add(required, name, path = name) if @script_hash.has_key?(name) if script_hash[name].path != path puts "[ERROR] Duplicated script name '#{name}'" set_error end return end script = ScriptFactory.create(required, name, path) script.checker = self @script_array.push(script) @script_hash[name] = script end # °ËÁõ ´ë»ó ½ºÅ©¸³Æ® °¹¼ö ¾ò±â def num_scripts @script_array.length end # ÁÖ¾îÁø À̸§¿¡ ¸ÊÇÎµÈ ½ºÅ©¸³Æ® °´Ã¼ ¾ò±â def get_script(name) @script_hash[name] end # °ËÁõ ½ÇÇà def run @script_array.each do |script| begin puts "Checking #{script.name}" script.check(@dir) rescue Exception => e puts '[ERROR] ' + e set_error end end end end