class ICU::TieBreak

This class is used to recognise the names of tie break rules. The class method identify takes a string as it’s only argument and returns a new intstance if it recognises a tie break rule from the string, or nil otherwise. An instance has three read-only methods: id (a shoet symbolic name), code (a two letter code) and name (the full name). For example:

ICU::TieBreak.identify("no such rule")           # => nil
tb = ICU::TieBreak.identify("Neustadlt")
tb.id                                            # => :neustadtl
tb.code                                          # => "SB"
tb.name                                          # => "Sonneborn-Berger"

The method is case insensitive and can cope with extraneous white space and, to a limited extent, name variations and spelling mistakes:

ICU::TieBreak.identify("SB").name                # => "Sonneborn-Berger"
ICU::TieBreak.identify("NESTADL").name           # => "Sonneborn-Berger"
ICU::TieBreak.identify(" wins ").name            # => "Number of wins"
ICU::TieBreak.identify(:sum_ratings).name        # => "Sum of opponent's ratings"
ICU::TieBreak.identify("median").name            # => "Harkness"
ICU::TieBreak.identify("MODIFIED").name          # => "Modified median"
ICU::TieBreak.identify("Modified\nMedian").name  # => "Modified median"
ICU::TieBreak.identify("\tbuccholts\t").name     # => "Buchholz"
ICU::TieBreak.identify("progressive\r\n").name   # => "Sum of progressive scores"
ICU::TieBreak.identify("SumOfCumulative").name   # => "Sum of progressive scores"

The full list of supported tie break rules is:

An array of all supported TieBreak instances (ordered by name) is returned by the class method rules.

rules = ICU::TieBreak.rules
rules.size                                       # => 9
rules.first.name                                 # => "Buchholz"

Note that this class only deals with the recognition of tie break names, not the calculation of tie break scores. The latter is currently implemented in the ICU::Tournament class.

Constants

RULES

Attributes

code[R]
id[R]
name[R]

Public Class Methods

identify(str) click to toggle source

Given a string, return the TieBreak rule it is recognised as, or return nil.

# File lib/icu_tournament/tie_break.rb, line 68
def self.identify(str)
  return nil unless str
  str = str.to_s.gsub(/\s+/, ' ').strip.downcase
  return nil if str.length <= 1 || str.length == 3
  RULES.each_pair { |id, rule| return new(id, rule[0], rule[1]) if str.upcase == rule[0] || str.match(rule[2]) }
  nil
end
rules() click to toggle source

Return an array of all tie break rules, ordered by name.

# File lib/icu_tournament/tie_break.rb, line 77
def self.rules
  RULES.keys.sort_by{ |id| RULES[id][1] }.inject([]) do |rules, id|
    rules << new(id, RULES[id][0], RULES[id][1])
  end
end