Last active
December 28, 2015 06:48
-
-
Save mertyildiran/7459266 to your computer and use it in GitHub Desktop.
HTML Tag Checker - Mehmet Mert Yildiran - 12060367
This file contains 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
# RUBY HTML TAG CHECKER | |
# MEHMET MERT YILDIRAN | |
# OGRENCI NO: 12060367 | |
# | |
# Ruby 2.0.0-p247 | |
# | |
# Örnek kullanım: | |
# html_filtrele("C:/Users/admin/Desktop/Specte.htm") | |
# html_tag_checker("C:/Users/admin/Desktop/Specte.htm") | |
# result = html_tag_checker("C:/Users/admin/Desktop/Specte.htm") | |
# * Örnekteki Specte.htm : http://specte.com/ index dosyasıdır. | |
def html_filtrele(address) | |
file = File.open(address) | |
contents = file.read | |
tags = Array.new | |
tags = contents.scan(Regexp.union(/<(\w+)[^>]*>/, /<\/(\w+)[^>]*>/)) | |
tags_clean = Array.new | |
i = 0 | |
while i < tags.length | |
if tags[i][1] == nil | |
tags_clean.push(tags[i][0]) | |
else | |
tags[i][1] = "/" + tags[i][1] | |
tags_clean.push(tags[i][1]) | |
end | |
i = i + 1 | |
end | |
return tags_clean | |
end | |
def html_tag_checker(address) | |
stack = Array.new | |
tags = Array.new | |
tags = html_filtrele(address) | |
tags.delete("base") | |
tags.delete("br") | |
tags.delete("col") | |
tags.delete("command") | |
tags.delete("embed") | |
tags.delete("hr") | |
tags.delete("img") | |
tags.delete("input") | |
tags.delete("link") | |
tags.delete("meta") | |
tags.delete("param") | |
tags.delete("source") | |
i = 0 | |
while i < tags.length | |
if tags[i].include?("/") | |
#tags[i].sub("/", "") | |
if tags[i] != "/" + stack.pop | |
return false | |
end | |
else | |
stack.push(tags[i]) | |
end | |
i = i + 1 | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment