Sha256: f7a30c0030cf60cace8e84cc86ada396b103e83276685304153f222b9985c46a
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module Revepast module Parser class EFT autoload :Utils, 'revepast/parser' include Revepast::Parser attr_reader :result, :bad_lines def initialize @Utils = Utils.new @result = {} @bad_lines = [] result = parse end def parse ammo_pattern = /^([\S ]+), ?([\S ]+)$/ blacklist = ['[empty high slot]', '[empty low slot]', '[empty medium slot]', '[empty rig slot]', '[empty subsystem slot]'] sanitize = @Utils.sanitize(Revepast.str) lines = [] sanitize.each do |line| unless blacklist.include? line.downcase lines << line end end begin lines.first =~ /^(\[).*(\])$/ ship = lines.first.match(ammo_pattern)[1].tr('[]', '') fit_name = lines.first.match(ammo_pattern)[2].tr('[]', '') rescue raise Unparsable.new("Invalid EFT title line") end matches, bad_lines = @Utils.regex_match_lines(ammo_pattern, lines[1..-1]) matches2, bad_lines2 = @Utils.parse_listing(bad_lines) @bad_lines = bad_lines2 module_w_ammo = Hash.new { |h, k| h[k] = 0 } matches.each do |m| module_w_ammo[m] += 1 end modules = [] module_w_ammo.sort.each do |(name, ammo), quantity| modules << { 'name'=> name.strip, 'ammo'=> ammo.strip, 'quantity'=> quantity} modules end matches2.each do |item| modules << item end @result = {'ship' => ship, 'name' => fit_name, 'modules' => modules.map { |i| i } } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
revepast-1.0.2 | lib/revepast/parser/eft.rb |
revepast-0.1.0 | lib/revepast/parser/eft.rb |
revepast-0.0.3 | lib/revepast/parser/eft.rb |