Class: Show::Gem::Junk::RubyGem

Inherits:
Object
  • Object
show all
Defined in:
lib/show/gem/junk/rubygem.rb

Overview

RubyGem is an unpacked gem on disk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RubyGem

Returns a new instance of RubyGem.



7
8
9
10
11
12
13
# File 'lib/show/gem/junk/rubygem.rb', line 7

def initialize(path)
  @path = File.expand_path(path)
  @name, _, @version = path.gsub(GEMS_DIR, '').rpartition('-')
  @files = Dir.glob("#{GEMS_DIR}#{name}-#{version}/**/*", File::FNM_DOTMATCH).map do |f|
    Show::Gem::Junk::GemFile.new(f)
  end
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/show/gem/junk/rubygem.rb', line 5

def files
  @files
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/show/gem/junk/rubygem.rb', line 5

def name
  @name
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/show/gem/junk/rubygem.rb', line 5

def path
  @path
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/show/gem/junk/rubygem.rb', line 5

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



33
34
35
# File 'lib/show/gem/junk/rubygem.rb', line 33

def <=>(other)
  percent_junk <=> other.percent_junk
end

#junk_filesObject



15
16
17
# File 'lib/show/gem/junk/rubygem.rb', line 15

def junk_files
  files.select(&:junk?)
end

#junk_sizeObject



23
24
25
# File 'lib/show/gem/junk/rubygem.rb', line 23

def junk_size
  junk_files.map(&:size).sum
end

#percent_junkObject



27
28
29
30
31
# File 'lib/show/gem/junk/rubygem.rb', line 27

def percent_junk
  return 0.0 if size.zero?

  (junk_size.to_f / size) * 100
end

#sizeObject



19
20
21
# File 'lib/show/gem/junk/rubygem.rb', line 19

def size
  files.map(&:size).sum
end