class ASF::Member

Public Class Methods

each(&block) click to toggle source

An iterator that returns a list of ids and associated members.txt entries.

# File lib/whimsy/asf/member.rb, line 18
def self.each(&block)
  new.each(&block)
end
emails(text) click to toggle source

extract member emails from members.txt entry

# File lib/whimsy/asf/member.rb, line 92
def self.emails(text)
  emails = text.to_s.scan(/Email: (.*(?:\n\s+\S+@.*)*)/).flatten.
    join(' ').split(/\s+/).grep(/@/)
end
find(id) click to toggle source

Determine if the person associated with a given id is an ASF member. Includes emeritus and deceased members Returns a boolean value.

# File lib/whimsy/asf/member.rb, line 86
def self.find(id)
  each {|availid| return true if availid == id}
  return false
end
find_by_email(value) click to toggle source

Find the ASF::Person associated with a given email

# File lib/whimsy/asf/member.rb, line 40
def self.find_by_email(value)
  value = value.downcase
  each do |id, text|
    emails(text).each do |email|
      return Person.find(id) if email.downcase == value
    end
  end
  nil
end
find_text_by_id(value) click to toggle source

Return the members.txt value assocaited with a given id

# File lib/whimsy/asf/member.rb, line 10
def self.find_text_by_id(value)
  new.each do |id, text|
    return text if id==value
  end
  nil
end
list() click to toggle source

return a list of members.txt entries as a Hash. Keys are availids. Values are a Hash with the following keys: :text, :name, "status".

# File lib/whimsy/asf/member.rb, line 25
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) click to toggle source

sort an entire members.txt file

# File lib/whimsy/asf/member.rb, line 106
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
status() click to toggle source

Return a hash of non-active ASF members and their status. Keys are availids. Values are strings from the section header under which the member is listed: currently either Emeritus (Non-voting) Member or Deceased Member.

# File lib/whimsy/asf/member.rb, line 54
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.to_s.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_change() click to toggle source

Return the Last Changed Date for members.txt in svn as a Time object.

# File lib/whimsy/asf/member.rb, line 99
def self.svn_change
  foundation = ASF::SVN['private/foundation']
  file = "#{foundation}/members.txt"
  return Time.parse(%x`svn info #{file}`[/Last Changed Date: (.*) \(/, 1]).gmtime
end
text() click to toggle source

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

# File lib/whimsy/asf/member.rb, line 133
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) click to toggle source

update local copy of members.txt

# File lib/whimsy/asf/member.rb, line 153
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

Public Instance Methods

each() { |id, sub(/\n.*\n===+\s*?\n(.*\n)+.*/,'').strip| ... } click to toggle source

An iterator that returns a list of ids and associated members.txt entries.

# File lib/whimsy/asf/member.rb, line 75
def each
  ASF::Member.text.to_s.split(/^ \*\) /).each do |section|
    id = section[/Avail ID: (.*)/,1]
    yield id, section.sub(/\n.*\n===+\s*?\n(.*\n)+.*/,'').strip if id
  end
  nil
end