Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubyXL'
- workbook = RubyXL::Workbook.new
- Sheet = workbook[0]
- Sheet.add_cell(0, 0, "Ars")
- Sheet.add_cell(0, 1, "Man")
- Sheet.add_cell(0, 2, "Ars-Man")
- Sheet.add_cell(0, 3, "Year")
- Sheet.add_cell(0, 4, "Winning")
- class Counter
- def initialize
- @line_num = 0
- @block_num = 0
- @ars_is_host = false
- end
- def reset_line
- @line_num = 0
- end
- def line
- @line_num
- end
- def next_line
- @line_num += 1
- end
- def block
- @block_num
- end
- def next_block
- @block_num += 1
- end
- def hosted_by_ars res
- @ars_is_host = res
- end
- def ars_is_host?
- @ars_is_host
- end
- end
- def parse_zero line, counter
- counter.next_block
- counter.reset_line
- end
- def parse_first line, counter
- day, s1, month, s2, year = line.match(/([0-9]+)( )([A-z]+)( )([0-9]{4})/).captures
- date = [day, month, year].join(' ')
- ::Sheet.add_cell(counter.block, 3, date)
- end
- def parse_second line, counter
- if "Arsenal v Manchester United".match(line)
- counter.hosted_by_ars true
- else
- counter.hosted_by_ars false
- end
- end
- def parse_fourth line, counter
- if counter.ars_is_host?
- s1, ars, b, man = line.match(/(.*">)([0-9]+)(-)([0-9]+)/).captures
- ::Sheet.add_cell(counter.block, 0, ars)
- ::Sheet.add_cell(counter.block, 1, man)
- else
- s1, man, b, ars = line.match(/(.*">)([0-9]+)(-)([0-9]+)/).captures
- ::Sheet.add_cell(counter.block, 0, ars)
- ::Sheet.add_cell(counter.block, 1, man)
- end
- ars_man = ars.to_i-man.to_i
- if ars_man > 0
- ::Sheet.add_cell(counter.block, 4, 1)
- elsif ars_man < 0
- ::Sheet.add_cell(counter.block, 4, -1)
- else
- ::Sheet.add_cell(counter.block, 4, 0)
- end
- ::Sheet.add_cell counter.block, 2, ars_man
- end
- counter = Counter.new
- File.open("untitled.txt").each do |line|
- if line.to_s.include? "<tr>"
- parse_zero line, counter
- else
- case counter.line
- when 1
- parse_first line, counter
- when 2
- parse_second line, counter
- when 4
- parse_fourth line, counter
- end
- end
- counter.next_line
- end
- workbook.write("./Ars3.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement