Class: Autoproj::Stats::Sanitizer
- Inherits:
-
Object
- Object
- Autoproj::Stats::Sanitizer
- Defined in:
- lib/autoproj/stats/sanitizer.rb
Overview
Class passed to the stats generators to sanitize names and compute copyright
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#licenses ⇒ Object
readonly
Returns the value of attribute licenses.
-
#simple_copyrights ⇒ Object
readonly
Returns the value of attribute simple_copyrights.
-
#timeline_affiliations ⇒ Object
readonly
Returns the value of attribute timeline_affiliations.
Instance Method Summary collapse
- #compute_copyright_of(author_name, date) ⇒ Object
-
#initialize(aliases: Hash.new) ⇒ Sanitizer
constructor
A new instance of Sanitizer.
- #license_of(pkg) ⇒ Object
- #load(path) ⇒ Object
- #sanitize_author_name(name) ⇒ Object
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
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/autoproj/stats/sanitizer.rb', line 6 def aliases @aliases end |
#licenses ⇒ Object (readonly)
Returns the value of attribute licenses.
9 10 11 |
# File 'lib/autoproj/stats/sanitizer.rb', line 9 def licenses @licenses end |
#simple_copyrights ⇒ Object (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_affiliations ⇒ Object (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
#compute_copyright_of(author_name, date) ⇒ Object
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(, date) if affiliation = simple_copyrights[] affiliation elsif timeline = timeline_affiliations[] timeline.inject("Unknown (#{})") do |aff, (new_aff, start_date)| if date < start_date return aff else new_aff end end else "Unknown (#{})" 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 (name) aliases[name] || name end |