Class: LinkmapIos::LinkmapParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ LinkmapParser

Returns a new instance of LinkmapParser.



12
13
14
15
16
# File 'lib/linkmap_ios.rb', line 12

def initialize(file_path)
  @file_path = file_path
  @id_map = {}
  @library_map = {}
end

Instance Attribute Details

#id_mapObject (readonly)

Returns the value of attribute id_map.



9
10
11
# File 'lib/linkmap_ios.rb', line 9

def id_map
  @id_map
end

#library_mapObject (readonly)

Returns the value of attribute library_map.



10
11
12
# File 'lib/linkmap_ios.rb', line 10

def library_map
  @library_map
end

Instance Method Details

#hashObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/linkmap_ios.rb', line 18

def hash
  # Cache
  return @result_hash if @result_hash

  parse

  total_size = @library_map.values.map(&:size).inject(:+)
  detail = @library_map.values.map { |lib| {:library => lib.name, :size => lib.size, :objects => lib.objects.map { |o| @id_map[o][:object] }}}

  # puts total_size
  # puts detail

  @result_hash = {:total => total_size, :detail => detail}
  @result_hash
end

#jsonObject



34
35
36
# File 'lib/linkmap_ios.rb', line 34

def json
  JSON.pretty_generate(hash)
end

#reportObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/linkmap_ios.rb', line 38

def report
  result = hash

  report = "# Total size\n"
  report << "#{Filesize.from(result[:total].to_s + 'B').pretty}\n"
  report << "\n# Library detail\n"
  result[:detail].sort_by { |h| h[:size] }.reverse.each do |lib|
    report << "#{lib[:library]}   #{Filesize.from(lib[:size].to_s + 'B').pretty}\n"
  end
  report << "\n# Object detail\n"
  @id_map.each_value do |id_info|
    report << "#{id_info[:object]}   #{Filesize.from(id_info[:size].to_s + 'B').pretty}\n"
  end

  report
end