Class: Autoproj::Stats::Sanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/stats/sanitizer.rb

Overview

Class passed to the stats generators to sanitize names and compute copyright

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aliases: Hash.new) ⇒ Sanitizer

Returns a new instance of Sanitizer.



11
12
13
14
15
# File 'lib/autoproj/stats/sanitizer.rb', line 11

def initialize(aliases: Hash.new)
    @simple_copyrights = Hash.new
    @timeline_affiliations = Hash.new
    @aliases = aliases
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



6
7
8
# File 'lib/autoproj/stats/sanitizer.rb', line 6

def aliases
  @aliases
end

#licensesObject (readonly)

Returns the value of attribute licenses.



9
10
11
# File 'lib/autoproj/stats/sanitizer.rb', line 9

def licenses
  @licenses
end

#simple_copyrightsObject (readonly)

Returns the value of attribute simple_copyrights.



7
8
9
# File 'lib/autoproj/stats/sanitizer.rb', line 7

def simple_copyrights
  @simple_copyrights
end

#timeline_affiliationsObject (readonly)

Returns the value of attribute timeline_affiliations.



8
9
10
# File 'lib/autoproj/stats/sanitizer.rb', line 8

def timeline_affiliations
  @timeline_affiliations
end

Instance Method Details



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/autoproj/stats/sanitizer.rb', line 40

def compute_copyright_of(author_name, date)
    if affiliation = simple_copyrights[author_name]
        affiliation
    elsif timeline = timeline_affiliations[author_name]
        timeline.inject("Unknown (#{author_name})") do |aff, (new_aff, start_date)|
            if date < start_date
                return aff
            else
                new_aff
            end
        end
    else
        "Unknown (#{author_name})"
    end
end

#license_of(pkg) ⇒ Object



32
33
34
# File 'lib/autoproj/stats/sanitizer.rb', line 32

def license_of(pkg)
    licenses[pkg.name]
end

#load(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/autoproj/stats/sanitizer.rb', line 17

def load(path)
    config = YAML.load(File.read(path))
    @aliases = config['aliases']
    @licenses = config['licenses'] || Hash.new
    if affiliations = config['affiliations']
        affiliations.each do |name, entry|
            if entry.respond_to?(:to_str)
                simple_copyrights[name] = entry
            else
                timeline_affiliations[name] = entry.sort_by(&:last)
            end
        end
    end
end

#sanitize_author_name(name) ⇒ Object



36
37
38
# File 'lib/autoproj/stats/sanitizer.rb', line 36

def sanitize_author_name(name)
    aliases[name] || name
end