Class: ASF::Member

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/whimsy/asf/member.rb

Constant Summary collapse

@@text =
nil
@@mtime =
0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.each(&block) ⇒ Object



16
17
18
# File 'lib/whimsy/asf/member.rb', line 16

def self.each(&block)
  new.each(&block)
end

.emails(text) ⇒ Object



77
78
79
80
# File 'lib/whimsy/asf/member.rb', line 77

def self.emails(text)
  emails = text.to_s.scan(/Email: (.*(?:\n\s+\S+@.*)*)/).flatten.
    join(' ').split(/\s+/).grep(/@/)
end

.find(id) ⇒ Object



72
73
74
75
# File 'lib/whimsy/asf/member.rb', line 72

def self.find(id)
  each {|availid| return true if availid == id}
  return false
end

.find_by_email(value) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/whimsy/asf/member.rb', line 34

def self.find_by_email(value)
  value = value.downcase
  each do |id, text|
    emails(text).each do |email|
      return Person[id] if email.downcase == value
    end
  end
  nil
end

.find_text_by_id(value) ⇒ Object



9
10
11
12
13
14
# File 'lib/whimsy/asf/member.rb', line 9

def self.find_text_by_id(value)
  new.each do |id, text|
    return text if id==value
  end
  nil
end

.listObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/whimsy/asf/member.rb', line 20

def self.list
  result = Hash[self.new.map {|id, text|
    # extract 1st line and remove any trailing /* comment */
    name = text[/(.*?)\n/, 1].sub(/\s+\/\*.*/,'')
    [id, {text: text, name: name}]
  }]

  self.status.each do |name, value|
    result[name]['status'] = value
  end

  result
end

.sort(source) ⇒ Object

sort an entire members.txt file



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/whimsy/asf/member.rb', line 89

def self.sort(source)
  # split into sections
  sections = source.split(/^([A-Z].*\n===+\n\n)/)

  # sort sections that contain names
  sections.map! do |section|
    next section unless section =~ /^\s\*\)\s/

    # split into entries, and normalize those entries
    entries = section.split(/^\s\*\)\s/)
    header = entries.shift
    entries.map! {|entry| " *) " + entry.strip + "\n\n"}

    # sort the entries
    entries.sort_by! do |entry|
      ASF::Person.sortable_name(entry[/\)\s(.*?)\s*(\/\*|$)/, 1])
    end

    header + entries.join
  end

  sections.join
end

.statusObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/whimsy/asf/member.rb', line 44

def self.status
  begin
    @status = nil if @mtime != @@mtime
    @mtime = @@mtime
    return Hash[@status.to_a] if @status
  rescue
  end

  status = {}
  sections = ASF::Member.text.split(/(.*\n===+)/)
  sections.shift(3)
  sections.each_slice(2) do |header, text|
    header.sub!(/s\n=+/,'')
    text.scan(/Avail ID: (.*)/).flatten.each {|id| status[id] = header}
  end

  @status = WeakRef.new(status)
  status
end

.svn_changeObject



82
83
84
85
86
# File 'lib/whimsy/asf/member.rb', line 82

def self.svn_change
  foundation = ASF::SVN['private/foundation']
  file = "#{foundation}/members.txt"
  return Time.parse(`svn info #{file}`[/Last Changed Date: (.*) \(/, 1]).gmtime
end

.textObject

cache the contents of members.txt. Primary purpose isn’t performance, but rather to have a local copy that can be updated and used until the svn working copy catches up



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/whimsy/asf/member.rb', line 116

def self.text
  foundation = ASF::SVN.find('private/foundation')
  return nil unless foundation

  begin
    text = @@text[0..-1] if @@text
  rescue WeakRef::RefError
    @@mtime = 0
  end

  if File.mtime("#{foundation}/members.txt").to_i > @@mtime.to_i
    @@mtime = File.mtime("#{foundation}/members.txt")
    text = File.read("#{foundation}/members.txt")
    @@text = WeakRef.new(text)
  end

  text
end

.text=(text) ⇒ Object

update local copy of members.txt



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/whimsy/asf/member.rb', line 136

def self.text=(text)
  # normalize text: sort and update active count
  text = ASF::Member.sort(text)
  pattern = /^Active.*?^=+\n+(.*?)^Emeritus/m
  text[/We now number (\d+) active members\./, 1] =
    text[pattern].scan(/^\s\*\)\s/).length.to_s

  # save
  @@mtime = Time.now
  @@text = WeakRef.new(text)
end

Instance Method Details

#eachObject



64
65
66
67
68
69
70
# File 'lib/whimsy/asf/member.rb', line 64

def each
  ASF::Member.text.split(/^ \*\) /).each do |section|
    id = section[/Avail ID: (.*)/,1]
    yield id, section.sub(/\n.*\n===+\s*?\n(.*\n)+.*/,'').strip if id
  end
  nil
end