def to_krause(rounds, arg)
      defaults = ICU::Tournament::Krause::OPTIONS.map(&:first)

      # Optional columns.
      case
      when arg[:except].instance_of?(Array)
        optional = (Set.new(defaults) - arg[:except].map!(&:to_s).map!(&:to_sym)).to_a
      when arg[:only].instance_of?(Array)
        optional = arg[:only].map!(&:to_s).map!(&:to_sym)
      else
        optional = defaults
      end
      optional = optional.inject({}) { |m, a| m[a] = true; m }

      # Get the values to use.
      val = defaults.inject({}) do |m, a|
        if optional[a]
          if arg[:fide] && (a == :rating || a == :id)
            m[a] = send("fide_#{a}")
          else
            m[a] = send(a)
          end
        end
        m
      end

      # Output the mandatory and optional values.
      krause = '001'
      krause << sprintf(' %4d', @num)
      krause << sprintf(' %1s', case val[:gender]; when 'M' then 'm'; when 'F' then 'w'; else ''; end)
      krause << sprintf(' %2s', case val[:title]; when nil then ''; when 'IM' then 'm'; when 'WIM' then 'wm'; else val[:title][0, val[:title].length-1].downcase; end)
      krause << sprintf(' %-33s', "#{@last_name},#{@first_name}")
      krause << sprintf(' %4s', val[:rating])
      krause << sprintf(' %3s', val[:fed])
      krause << sprintf(' %11s', val[:id])
      krause << sprintf(' %10s', val[:dob])
      krause << sprintf(' %4.1f', points)
      krause << sprintf(' %4s', val[:rank])

      # And finally the round scores.
      (1..rounds).each do |r|
        result = find_result(r)
        krause << sprintf('  %8s', result ? result.to_krause : '')
      end
      krause << "\n"
    end
def to_krause(rounds, arg)
      defaults = ICU::Tournament::Krause::OPTIONS.map(&:first)

      # Optional columns.
      case
      when arg[:except].instance_of?(Array)
        optional = (Set.new(defaults) - arg[:except].map!(&:to_s).map!(&:to_sym)).to_a
      when arg[:only].instance_of?(Array)
        optional = arg[:only].map!(&:to_s).map!(&:to_sym)
      else
        optional = defaults
      end
      optional = optional.inject({}) { |m, a| m[a] = true; m }

      # Get the values to use.
      val = defaults.inject({}) do |m, a|
        if optional[a]
          if arg[:fide] && (a == :rating || a == :id)
            m[a] = send("fide_#{a}")
          else
            m[a] = send(a)
          end
        end
        m
      end

      # Output the mandatory and optional values.
      krause = '001'
      krause << sprintf(' %4d', @num)
      krause << sprintf(' %1s', case val[:gender]; when 'M' then 'm'; when 'F' then 'w'; else ''; end)
      krause << sprintf(' %2s', case val[:title]; when nil then ''; when 'IM' then 'm'; when 'WIM' then 'wm'; else val[:title][0, val[:title].length-1].downcase; end)
      krause << sprintf(' %-33s', "#{@last_name},#{@first_name}")
      krause << sprintf(' %4s', val[:rating])
      krause << sprintf(' %3s', val[:fed])
      krause << sprintf(' %11s', val[:id])
      krause << sprintf(' %10s', val[:dob])
      krause << sprintf(' %4.1f', points)
      krause << sprintf(' %4s', val[:rank])

      # And finally the round scores.
      (1..rounds).each do |r|
        result = find_result(r)
        krause << sprintf('  %8s', result ? result.to_krause : '')
      end
      krause << "\n"
    end
Format a player's 001 record as it would appear in a Krause formatted file (including the final newline).