class SwissMatch::District

Represents a swiss district.

Attributes

canton[R]
communities[R]

@return [SwissMatch::Communities]

The political communities belonging to this district
district_number[R]

@return [String]

The district number.
name[R]

@return [String]

The name of the district.
to_s[R]

@return [String]

The name of the district.

Public Class Methods

new(district_number, name, canton, communities) click to toggle source

@param [String] district_number

The two letter abbreviation of the districts name as used on license plates.

@param [String] name

The official name of the district.

@param [SwissMatch::Canton] canton

The canton this district belongs to

@param [SwissMatch::Communities] communities

The communities belonging to this district
# File lib/swissmatch/district.rb, line 32
def initialize(district_number, name, canton, communities)
  @district_number  = district_number
  @name             = name
  @canton           = canton
  @communities      = communities
end

Public Instance Methods

eql?(other) click to toggle source

@private @see Object#eql?

# File lib/swissmatch/district.rb, line 72
def eql?(other)
  self.class.eql?(other.class) && @number.eql?(other.number)
end
hash() click to toggle source

@private @see Object#hash

# File lib/swissmatch/district.rb, line 66
def hash
  [self.class, @number].hash
end
inspect() click to toggle source

@return [String] @see Object#inspect

# File lib/swissmatch/district.rb, line 78
def inspect
  sprintf "\#<%s:%014x %d %p>", self.class, object_id, @district_number, to_s
end
to_hash(retain_references=false) click to toggle source

@param [Boolean] retain_references

If set to false, :agglomeration will be set to the community_number and
:canton to the canton's license_tag.

@return [Hash]

All properties of the district as a hash.
# File lib/swissmatch/district.rb, line 45
def to_hash(retain_references=false)
  if retain_references
    canton        = @canton
    communities   = @communities
  else
    canton        = @canton && @canton.license_tag
    communities   = @communities.map(&:community_number)
  end

  {
    :name             => @name,
    :district_number  => @district_number,
    :canton           => canton,
    :communities      => communities,
  }
end