class SwissMatch::Districts

Represents a collection of swiss districts and provides a query interface.

Public Class Methods

new(districts) click to toggle source

@param [Array<SwissMatch::District>] districts

The SwissMatch::District objects this SwissMatch::Districts should contain
# File lib/swissmatch/districts.rb, line 17
def initialize(districts)
  @districts          = districts
  @by_district_number = {}
  @by_name            = {}

  districts.each do |district|
    @by_district_number[district.district_number] = district
    @by_name[district.name]                       = district
  end
end

Public Instance Methods

[](district_number_or_name) click to toggle source

@return [SwissMatch::District]

The district with the given district_number or name
# File lib/swissmatch/districts.rb, line 86
def [](district_number_or_name)
  @by_district_number[district_number_or_name] || @by_name[district_number_or_name]
end
by_district_number(tag) click to toggle source

@return [SwissMatch::District]

The district with the given license tag.
# File lib/swissmatch/districts.rb, line 92
def by_district_number(tag)
  @by_district_number[tag]
end
by_name(name) click to toggle source

@return [SwissMatch::District]

The district with the given name (any language)
# File lib/swissmatch/districts.rb, line 98
def by_name(name)
  @by_name[name]
end
each(&block) click to toggle source

Calls the block once for every SwissMatch::District in this SwissMatch::Districts instance, passing that district as a parameter. The order is the same as the instance was constructed.

@yield [district] @yieldparam [SwissMatch::District] district

@return [self] Returns self

# File lib/swissmatch/districts.rb, line 36
def each(&block)
  @districts.each(&block)
  self
end
inspect() click to toggle source

@private @see Object#inspect

# File lib/swissmatch/districts.rb, line 115
def inspect
  sprintf "\#<%s:%x size: %d>", self.class, object_id>>1, size
end
reject(*args, &block) click to toggle source

@return [SwissMatch::Districts]

A SwissMatch::Districts collection with all SwissMatch::District objects for which the block
returned false (or a falseish value)
# File lib/swissmatch/districts.rb, line 64
def reject(*args, &block)
  Districts.new(@districts.reject(*args, &block))
end
reverse_each(&block) click to toggle source

Calls the block once for every SwissMatch::District in this SwissMatch::Districts instance, passing that district as a parameter. The order is the reverse of what the instance was constructed.

@yield [district] @yieldparam [SwissMatch::District] district

@return [self] Returns self

# File lib/swissmatch/districts.rb, line 49
def reverse_each(&block)
  @districts.reverse_each(&block)
  self
end
select(*args, &block) click to toggle source

@return [SwissMatch::Districts]

A SwissMatch::Districts collection with all SwissMatch::District objects for which the block
returned true (or a trueish value)
# File lib/swissmatch/districts.rb, line 57
def select(*args, &block)
  Districts.new(@districts.select(*args, &block))
end
size() click to toggle source

@return [Integer] The number of SwissMatch::District objects in this collection.

# File lib/swissmatch/districts.rb, line 103
def size
  @districts.size
end
sort(*args, &block) click to toggle source

@see Enumerable#sort

@return [SwissMatch::Districts]

A SwissMatch::Districts collection sorted by the block
# File lib/swissmatch/districts.rb, line 72
def sort(*args, &block)
  Districts.new(@districts.sort(*args, &block))
end
sort_by(*args, &block) click to toggle source

@see Enumerable#sort_by

@return [SwissMatch::Districts]

A SwissMatch::Districts collection sorted by the block
# File lib/swissmatch/districts.rb, line 80
def sort_by(*args, &block)
  Districts.new(@districts.sort_by(*args, &block))
end
to_a() click to toggle source

@return [Array<SwissMatch::District>]

An Array with all SwissMatch::District objects in this SwissMatch::Districts.
# File lib/swissmatch/districts.rb, line 109
def to_a
  @districts.dup
end