lib/revepast/parser/eft.rb in revepast-0.0.2 vs lib/revepast/parser/eft.rb in revepast-0.0.3
- old
+ new
@@ -4,31 +4,40 @@
autoload :Utils, 'revepast/parser'
include Revepast::Parser
attr_reader :result, :bad_lines
- def initialize(str)
+ def initialize
@Utils = Utils.new
@result = {}
@bad_lines = []
- result = parse(@Utils.sanitize(str))
+ result = parse
end
- def parse(str)
+ def parse
ammo_pattern = /^([\S ]+), ?([\S ]+)$/
blacklist = ['[empty high slot]',
'[empty low slot]',
'[empty medium slot]',
'[empty rig slot]',
'[empty subsystem slot]']
- if str.lines.first =~ /^(\[).*(\])$/
- ship = str.lines.first.match(ammo_pattern)[1].tr('[]', '')
- fit_name = str.lines.first.match(ammo_pattern)[2].tr('[]', '')
- else
- puts "Invalid EFT title line"
+ 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, str.lines[1..-1])
+ 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 }
\ No newline at end of file