def initialize(current_statistics_page, resource, logger)
header_is_not_ended = true
tables_is_not_ended = true
summary_table_header_is_not_ended = true
footer_is_not_ended = true
number_of_parsed_tables = 0
tables = ''
current_statistics_page.split(/\n/).each do |line|
if header_is_not_ended then
if line.index(Regexp.new(resource.table_Infos.first.label)) != nil then
header_is_not_ended = false
else
next
end
end
if tables_is_not_ended then
tables += line + "\n"
if line.index(/^\|\}/) != nil then
number_of_parsed_tables += 1
if number_of_parsed_tables >= resource.table_Infos.size() then
tables = tables.lstrip()
tables_is_not_ended = false
end
end
next
end
end
sequence_of_wiki_row = ''
tables.split(/\n/).each do |line|
if /\|.*/.match(line) != nil then
sequence_of_wiki_row += (line + "\n")
end
end
wiki_rows = sequence_of_wiki_row.split(/^\|-\s*\n/)
@rows = Array.new
wiki_rows.each do |wiki_row|
wiki_fields = wiki_row.split("\n")
match_data = /\[\[\:?(.+)\:?\|(.+)\]\]/.match(wiki_fields[3])
if match_data == nil then
next
end
code = match_data[2]
field1 = field_value(wiki_fields[1])
splitted_description = field1.split(/\s+-\s+/)
if splitted_description.size == 2 then
description = splitted_description[0]
article_of_wiki = splitted_description[1].sub(/\[\[/, '').sub(/\|.+\]\]/, '')
elsif splitted_description.size == 1 then
description = splitted_description[0]
article_of_wiki = ''
else
logger.log('Language description parse error: ' + field1)
exit(1)
end
english_description = field_value(wiki_fields[2])
score = field_value(wiki_fields[12])
row = WikiTableRow.new(code, description, article_of_wiki, english_description, score)
@rows.push(row)
end
end