class ASF::OrgChart

Reads and provides access to the officers/personnel-duties/ROLENAME.yaml files.

Public Class Methods

[](name) click to toggle source

Access data from a specific role

# File lib/whimsy/asf/orgchart.rb, line 72
def self.[](name)
  self.load
  @@duties[name]
end
desc() click to toggle source

Access descriptions of the ['info'] section fields

# File lib/whimsy/asf/orgchart.rb, line 79
def self.desc
  self.load
  @@desc
end
load() click to toggle source

parse any changed YAML role files.

# File lib/whimsy/asf/orgchart.rb, line 23
def self.load
  @@source ||= ASF::SVN['personnel-duties']
  Dir[File.join(@@source, '*.txt')].each do |file|
    name = file[/.*\/(.*?)\.txt/, 1]
    next if @@duties[name] and @@duties[name]['mtime'] > File.mtime(file).to_f
    data = Hash[*File.read(file).split(/^\[(.*)\]\n/)[1..-1].map(&:strip)]
    next unless data['info']
    data['info'] = YAML.safe_load(data['info'])
    name = @@aliases[name] || name
    # fix up data items available from elsewhere
    if name =~ %r{^vp-(.+)$} or name =~ %r{^(security)$}
      post = $1
      begin
        data['info']['id'] = ASF::Committee[post].chairs.map {|a| a[:id]}
      rescue
        begin
          data['info']['id'] = ASF::Committee.officers.select{|o| o.name == post}.first.chairs.map {|a| a[:id]}
        rescue
          Wunderbar.info "Cannot find chair for #{name}"
        end
      end
    else
      tmp = ASF::Committee.officers.select{|o| o.name == name}.first
      if tmp
        data['info']['id'] = tmp.chairs.map {|a| a[:id]}
      else
        Wunderbar.info "Cannot find chair for #{name}"
      end
    end
    data['mtime'] = File.mtime(file).to_f
    @@duties[name] = data
  end

  file = File.join(@@source, 'README')
  unless @@desc['mtime'] and @@desc['mtime'] > File.mtime(file).to_f
    data = Hash[*File.read(file).split(/^\[(.*)\]\n/)[1..-1].map(&:strip)]
    if data['info']
      data = YAML.safe_load(data['info'])
      data['mtime'] = File.mtime(file).to_f
      @@desc = data
    end
  end

  @@duties
end