Module: SupCom2ReplayParser
- Extended by:
- SupCom2ReplayParser
- Included in:
- SupCom2ReplayParser
- Defined in:
- lib/supcom2_replay_parser.rb,
lib/supcom2_replay_parser/data.rb,
lib/supcom2_replay_parser/game_options.rb,
lib/supcom2_replay_parser/players_info.rb
Defined Under Namespace
Modules: Data, GameOptions, PlayersInfo
Constant Summary collapse
- ALLOWED_EXTENSION =
'.SC2ReplayDLC'
Instance Method Summary collapse
Instance Method Details
#call(filepath) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/supcom2_replay_parser.rb', line 11 def call(filepath) raise Exception, "Allowed only files with extension #{ALLOWED_EXTENSION}" unless allow_file_extension?(filepath) replay_info = {} file_lines = File.new(filepath, encoding: 'ISO-8859-1:UTF-8') file_lines.each do |line| current_line = file_lines.lineno if current_line == 1 replay_info[:game_version] = line.sub(/[[:cntrl:]]/, '').chomp end if current_line == 2 replay_info[:replay_version] = line.sub(/[[:cntrl:]]/, '').chomp end if current_line == 4 || current_line == 5 next if !has_line_full_needed_data?(line) && current_line == 4 raise Exception, 'Replay is broken' unless has_line_full_needed_data?(line) replay_info.merge!({ players_info: PlayersInfo.call(line), game_options: GameOptions.call(line) }) break end end raise Exception, 'Replay is broken' if replay_info.empty? replay_info end |