Last active
August 29, 2015 14:16
-
-
Save isubas/d36bc28ca137f4a0d257 to your computer and use it in GitHub Desktop.
".rtf" Uzantılı Dosyadan Belirli Bir Düzene Göre Belirlenmiş Soruların Verini Okuma
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
# encoding: UTF-8 | |
require 'yomu' | |
data = File.read 'deneme.rtf' | |
text = Yomu.read :text, data | |
# Soru ayrımların belirlendiği değişken | |
config = {option_separate: ")", question_info: "#", question_separate: "."} | |
# Seçenek değerlerinin belirlendiği değişken | |
options_keys = options_keys = %w[A B C D E] .collect { |x| x + config[:option_separate]} | |
# Soru içeriğinin başlama durumu | |
question_content_start_status = false | |
# Soru seçeneklerinin başlama durumu | |
question_option_start_status = false | |
# Soru içeriği | |
question_content = "" | |
# Seçenek içeriği | |
question_option_content = "" | |
# Seçeneklerin başlangıç değeri | |
option_key = "A" | |
# Dosyadaki toplam satır sayısı | |
lines_count = text.lines.count | |
text.lines.each_with_index do |line , index| | |
# Satırın birinci değeri "#"'mi? | |
# "#" Soruya başlangıç değerini gösterir. | |
# "#" ile başlayan satır soru bilgilerini içinde barındırır.( | |
# 1.C.3 => 1-> soru numarası, C-> Doğru Cevap, 3-> Sorunun tahmini zorluk derecesi | |
if line[0]==config[:question_info] | |
# Eğer son seçenekte kalındıysa bunu bastır. | |
if option_key == "E" | |
puts "Seçenek: " + option_key + " İçerik: " + question_option_content.gsub("\n", "") | |
question_option_content = "" | |
option_key = "A" | |
end | |
question_option_start_status = false | |
question_info = line.gsub(config[:question_info], '').split(config[:question_separate]) | |
question_number = question_info[0] | |
question_answer = question_info[1] | |
puts "Soru No: " + question_number + " Doğru Cevap: " + question_answer | |
question_content_start_status = true | |
next | |
end | |
# Soru içeriğinin okunduğu bölüm | |
if question_content_start_status && line[0] != config[:question_info] | |
unless options_keys.include?(line[0..1]) | |
question_content = question_content + line | |
else | |
puts "Soru İçeriği: " + question_content | |
question_content = "" | |
question_content_start_status = false | |
question_option_start_status = true | |
end | |
end | |
# Soru seçeneklerinin okunduğu bölüm | |
if question_option_start_status && line[0] != config[:question_info] | |
if options_keys.include?(line[0..1]) | |
if (option_key + config[:option_separate]) != line[0..1] | |
puts "Seçenek: " + option_key + " İçerik: " + question_option_content.gsub("\n", "") | |
question_option_content = "" | |
option_key = line.strip[0] | |
end | |
question_option_content = question_option_content + line.gsub(line[0..1], "") | |
else | |
question_option_content = question_option_content + line | |
end | |
end | |
# Son satıra gelindiyse yapılacak durum | |
if lines_count == index+1 | |
puts "Seçenek: " + option_key + " İçerik: " + question_option_content.gsub("\n", "") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment