Class: D3MPQ::ModCodeAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/d3_mpq/mod_code_analyzer.rb

Constant Summary collapse

SEPERATOR =
","

Instance Method Summary collapse

Constructor Details

#initialize(parser, files, output = nil) ⇒ ModCodeAnalyzer

Returns a new instance of ModCodeAnalyzer.



5
6
7
8
9
# File 'lib/d3_mpq/mod_code_analyzer.rb', line 5

def initialize(parser, files, output = nil)
  @parser     = parser.new
  @files      = [*files]
  @output     = output || "mod_code"
end

Instance Method Details

#attributesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/d3_mpq/mod_code_analyzer.rb', line 22

def attributes
  return @attributes if @attributes

  h = Hash.new { |h,k| h[k] = [] }
  mod_codes.each do |e|
    mod_code = e[:mod_code]
    h[mod_code.mod_code] << e[:name] if mod_code.mod_code != 0xFFFFFFFF
  end

  @attributes = []
  h.each do |mod_code, names|
    @attributes << { :mod_code => mod_code, :names => names }
  end
  @attributes.sort! { |x, y| y[:names].length <=> x[:names].length }

  return @attributes
end

#mod_codesObject

HACK: hacky implementation right here right now



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/d3_mpq/mod_code_analyzer.rb', line 41

def mod_codes
  return @mod_codes if @mod_codes

  @mod_codes = []
  snapshots.each do |s|
    s.content.each.each do |i|
      i.mod_codes.each do |mod_code|
        @mod_codes << {:mod_code => mod_code, :name => i.name}
      end
    end
  end

  return @mod_codes
end

#writeObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/d3_mpq/mod_code_analyzer.rb', line 11

def write
#      puts attributes
  s = ["ModCode"]
  attributes.each do |e|
    s << "#{e[:mod_code]}#{SEPERATOR}" + e[:names].join(SEPERATOR)
  end

  path = File.join("analyze", @output)
  File.open("#{path}.csv", 'w') { |f| f.write(s.join("\n")) }
end