Class: Vernier::Output::FilenameFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/output/filename_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilenameFilter



6
7
8
9
10
11
# File 'lib/vernier/output/filename_filter.rb', line 6

def initialize
  @pwd = "#{Dir.pwd}/"
  @gem_regex = %r{\A#{Regexp.union(Gem.path)}/gems/}
  @gem_match_regex = %r{\A#{Regexp.union(Gem.path)}/gems/([a-zA-Z](?:[a-zA-Z0-9\.\_]|-[a-zA-Z])*)-([0-9][0-9A-Za-z\-_\.]*)/(.*)\z}
  @rubylibdir = "#{RbConfig::CONFIG["rubylibdir"]}/"
end

Instance Attribute Details

#gem_match_regexObject (readonly)

Returns the value of attribute gem_match_regex.



13
14
15
# File 'lib/vernier/output/filename_filter.rb', line 13

def gem_match_regex
  @gem_match_regex
end

#gem_regexObject (readonly)

Returns the value of attribute gem_regex.



13
14
15
# File 'lib/vernier/output/filename_filter.rb', line 13

def gem_regex
  @gem_regex
end

#pwdObject (readonly)

Returns the value of attribute pwd.



13
14
15
# File 'lib/vernier/output/filename_filter.rb', line 13

def pwd
  @pwd
end

#rubylibdirObject (readonly)

Returns the value of attribute rubylibdir.



13
14
15
# File 'lib/vernier/output/filename_filter.rb', line 13

def rubylibdir
  @rubylibdir
end

Instance Method Details

#call(filename) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vernier/output/filename_filter.rb', line 15

def call(filename)
  if filename.match?(gem_regex)
    gem_match_regex =~ filename
    "gem:#$1-#$2:#$3"
  elsif filename.start_with?(pwd)
    filename.delete_prefix(pwd)
  elsif filename.start_with?(rubylibdir)
    path = filename.delete_prefix(rubylibdir)
    "rubylib:#{RUBY_VERSION}:#{path}"
  else
    filename
  end
end