Class: ASF::ICLA

Inherits:
Object
  • Object
show all
Defined in:
lib/whimsy/asf/icla.rb

Constant Summary collapse

OFFICERS =
ASF::SVN['private/foundation/officers']
SOURCE =
OFFICERS ? "#{OFFICERS}/iclas.txt" : nil
SUFFIXES =
/^([Jj][Rr]\.?|I{2,3}|I?V|VI{1,3}|[A-Z]\.)$/
@@mtime =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#claRefObject

cla name or SVN revision info



7
8
9
# File 'lib/whimsy/asf/icla.rb', line 7

def claRef
  @claRef
end

#emailObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



6
7
8
# File 'lib/whimsy/asf/icla.rb', line 6

def email
  @email
end

#formObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



6
7
8
# File 'lib/whimsy/asf/icla.rb', line 6

def form
  @form
end

#idObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



6
7
8
# File 'lib/whimsy/asf/icla.rb', line 6

def id
  @id
end

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



6
7
8
# File 'lib/whimsy/asf/icla.rb', line 6

def legal_name
  @legal_name
end

#nameObject

N.B. only id and name should be considered public form and claRef may contain details of the legal name beyond that in the public name



6
7
8
# File 'lib/whimsy/asf/icla.rb', line 6

def name
  @name
end

Class Method Details

.asciize(name) ⇒ Object

sort support



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/whimsy/asf/icla.rb', line 125

def self.asciize(name)
  if name.match /[^\x00-\x7F]/
    # digraphs.  May be culturally sensitive
    name.gsub! /\u00df/, 'ss'
    name.gsub! /\u00e4|a\u0308/, 'ae'
    name.gsub! /\u00e5|a\u030a/, 'aa'
    name.gsub! /\u00e6/, 'ae'
    name.gsub! /\u00f1|n\u0303/, 'ny'
    name.gsub! /\u00f6|o\u0308/, 'oe'
    name.gsub! /\u00fc|u\u0308/, 'ue'

    # latin 1
    name.gsub! /[\u00e0-\u00e5]/, 'a'
    name.gsub! /\u00e7/, 'c'
    name.gsub! /[\u00e8-\u00eb]/, 'e'
    name.gsub! /[\u00ec-\u00ef]/, 'i'
    name.gsub! /[\u00f2-\u00f6]|\u00f8/, 'o'
    name.gsub! /[\u00f9-\u00fc]/, 'u'
    name.gsub! /[\u00fd\u00ff]/, 'y'

    # Latin Extended-A
    name.gsub! /[\u0100-\u0105]/, 'a'
    name.gsub! /[\u0106-\u010d]/, 'c'
    name.gsub! /[\u010e-\u0111]/, 'd'
    name.gsub! /[\u0112-\u011b]/, 'e'
    name.gsub! /[\u011c-\u0123]/, 'g'
    name.gsub! /[\u0124-\u0127]/, 'h'
    name.gsub! /[\u0128-\u0131]/, 'i'
    name.gsub! /[\u0132-\u0133]/, 'ij'
    name.gsub! /[\u0134-\u0135]/, 'j'
    name.gsub! /[\u0136-\u0138]/, 'k'
    name.gsub! /[\u0139-\u0142]/, 'l'
    name.gsub! /[\u0143-\u014b]/, 'n'
    name.gsub! /[\u014C-\u0151]/, 'o'
    name.gsub! /[\u0152-\u0153]/, 'oe'
    name.gsub! /[\u0154-\u0159]/, 'r'
    name.gsub! /[\u015a-\u0162]/, 's'
    name.gsub! /[\u0162-\u0167]/, 't'
    name.gsub! /[\u0168-\u0173]/, 'u'
    name.gsub! /[\u0174-\u0175]/, 'w'
    name.gsub! /[\u0176-\u0178]/, 'y'
    name.gsub! /[\u0179-\u017e]/, 'z'

    # denormalized diacritics
    name.gsub! /[\u0300-\u036f]/, ''
  end

  name.strip.gsub /[^\w]+/, '-'
end

.availidsObject

list of all ids



87
88
89
90
91
92
93
94
# File 'lib/whimsy/asf/icla.rb', line 87

def self.availids
  return unless SOURCE
  refresh
  return @@availids if @@availids
  availids = []
  each {|icla| availids << icla.id unless icla.id == 'notinavail'}
  @availids = availids
end

.each(&block) ⇒ Object

iterate over all of the ICLAs



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/whimsy/asf/icla.rb', line 97

def self.each(&block)
  refresh
  if @@id_index and not @@id_index.empty?
    @@id_index.values.each(&block)
  elsif @@email_index and not @@email_index.empty?
    @@email_index.values.each(&block)
  elsif @@name_index and not @@name_index.empty?
    @@name_index.values.each(&block)
  elsif SOURCE and File.exist?(SOURCE)
    File.read(SOURCE).scan(/^([-\w]+):(.*?):(.*?):(.*?):(.*)/).each do |list|
      icla = ICLA.new()
      icla.id = list[0]
      icla.legal_name = list[1]
      icla.name = list[2]
      icla.email = list[3]
      icla.form = list[4]
      match = icla.form.match(/^Signed CLA(?:;(\S+)| \((\+=.+)\))/)
      if match
        # match either the cla name or the SVN ref (+=...)
        icla.claRef = match[1] || match[2]
      end
      block.call(icla)
    end
  end
end

.find_by_email(value) ⇒ Object

find ICLA by email



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/whimsy/asf/icla.rb', line 62

def self.find_by_email(value)
  return unless SOURCE

  refresh
  unless @@email_index
    @@email_index = {}
    each {|icla| @@email_index[icla.email.downcase] = icla}
  end

  @@email_index[value.downcase]
end

.find_by_id(value) ⇒ Object

find ICLA by ID



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/whimsy/asf/icla.rb', line 49

def self.find_by_id(value)
  return if value == 'notinavail' or not SOURCE

  refresh
  unless @@id_index
    @@id_index = {}
    each {|icla| @@id_index[icla.id] = icla}
  end

  @@id_index[value]
end

.find_by_name(value) ⇒ Object

find ICLA by name



75
76
77
78
79
80
81
82
83
84
# File 'lib/whimsy/asf/icla.rb', line 75

def self.find_by_name(value)
  return unless SOURCE
  refresh
  unless @@name_index
    @@name_index = {}
    each {|icla| @@name_index[icla.name] = icla}
  end

  @@email_index[value]
end

.lname(line) ⇒ Object

rearrange line in an order suitable for sorting



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/whimsy/asf/icla.rb', line 178

def self.lname(line)
  return '' if line.start_with? '#'
  id, name, rest = line.split(':',3)
  return '' unless name

  # Drop trailing (comment string) or /* comment */
  name.sub! /\(.+\)$/,''
  name.sub! /\/\*.+\*\/$/,''
  return '' if name.strip.empty?

  name = name.split.reverse
  suffix = (name.shift if name.first =~ SUFFIXES)
  suffix += ' ' + name.shift if name.first =~ SUFFIXES
  name << name.shift
  name << name.shift if name.first=='Lewis' and name.last=='Ship'
  name << name.shift if name.first=='Gallardo' and name.last=='Rivera'
  name << name.shift if name.first=="S\u00e1nchez" and name.last=='Vega'
  # name << name.shift if name.first=='van'
  name.last.sub! /^IJ/, 'Ij'
  name.unshift(suffix) if suffix
  name.map! {|word| asciize(word)}
  name = name.reverse.join(' ')

  "#{name}:#{rest}"
end

.preloadObject

load ICLA information for every committer



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/whimsy/asf/icla.rb', line 36

def self.preload
  people = []
  each do |icla|
    unless icla.id == 'notinaval'
      person = ASF::Person.find(icla.id)
      people << person
      person.icla = icla
    end
  end
  people
end

.refreshObject

flush caches if source file changed



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/whimsy/asf/icla.rb', line 15

def self.refresh
  if not SOURCE or File.mtime(SOURCE) != @@mtime
    @@mtime = SOURCE ? File.mtime(SOURCE) : Time.now
    @@id_index = nil
    @@email_index = nil
    @@name_index = nil
    @@svn_change = nil

    @@availids = nil
  end
end

.sort(source) ⇒ Object

sort an entire iclas.txt file



205
206
207
208
209
210
211
# File 'lib/whimsy/asf/icla.rb', line 205

def self.sort(source)
  headers = source.scan(/^#.*/)
  lines = source.scan(/^\w.*/)

  headers.join("\n") + "\n" + 
    lines.sort_by {|line| lname(line + "\n")}.join("\n") + "\n"
end

.svn_changeObject



27
28
29
30
31
32
33
# File 'lib/whimsy/asf/icla.rb', line 27

def self.svn_change
  self.refresh
  if SOURCE
    @@svn_change ||= Time.parse(
      `svn info #{SOURCE}`[/Last Changed Date: (.*) \(/, 1]).gmtime
  end
end