parse

in lib/whimsy/asf/agenda.rb [86:177]


  def parse(file, quick=false)
    @file = file
    @quick = quick

    unless @file.valid_encoding?
      filter = proc {|c| c.unpack1('U') rescue 0xFFFD}
      @file = @file.chars.map(&filter).pack('U*').force_encoding('utf-8')
    end

    @@parsers.each { |parser| instance_exec(&parser) }

    
    CONTENTS.each do |section, index|
      @sections[section][:index] = index if @sections[section]
    end

    
    return [] if @sections.empty?

    
    flagged_reports = Hash[@file[/ \d\. Committee Reports.*?\n\s+A\./m].
      scan(/

    president = @sections.values.find {|item| item['title'] == 'President'}
    return [] unless president 
    pattach = president['report'][/\d+ through \d+\.$/]
    
    preports = Range.new(*pattach.scan(/\d+/)) if pattach
    
    @sections.each do |section, hash|
      text = hash['text'] || hash['report']
      if text
        text.sub!(/\A\s*\n/, '')
        text.sub!(/\s+\Z/, '')
        unindent = text.sub(/s+\Z/, '').scan(/^ *\S/).map(&:length).min || 1
        text.gsub!(/^ {
      end

      text = hash['comments']
      if text
        text.sub!(/\A\s*\n/, '')
        text.sub!(/\s+\Z/, '')
        unindent = text.sub(/s+\Z/, '').scan(/^ *\S/).map(&:length).min || 1
        text.gsub!(/^ {
      end

      
      flags = flagged_reports[hash['title']]
      hash['flagged_by'] = flags.split(', ') if flags

      
      hash['to'] = 'president' if preports&.include?(section)
    end

    unless @quick
      
      whimsy = 'https://whimsy.apache.org'
      @sections.each do |section, hash|
        next unless section =~ /^(4[A-Z]|\d+|[A-Z][A-Z]?)$/
        committee = ASF::Committee.find(hash['title'] ||= 'UNKNOWN')
        unless section =~ /^4[A-Z]$/
          hash['roster'] =
            "#{whimsy}/roster/committee/#{CGI.escape committee.name}"
        end
        if section =~ /^[A-Z][A-Z]?$/
          hash['stats'] = 'https://reporter.apache.org/wizard/statistics?' +
            CGI.escape(committee.name)
        end
        hash['prior_reports'] = minutes(committee.display_name)
      end
    end

    
    @sections.each do |section, hash|
      hash[:attach] = section

      
      hash['title'] ||= 'UNKNOWN'

      if hash['title'] == 'UNKNOWN'
        hash['warnings'] = ['unable to find attachment']
      end
    end

    
    if @sections.values.first['timestamp'] > @sections.values.last['timestamp']
      @sections.values.last['timestamp'] += 86_400_000 
    end

    @sections.values
  end