class SwissMatch::Community

Represents a swiss community. Swiss communities are identified by their community number (BFSNR).

Attributes

agglomeration[R]

@return [SwissMatch::Community]

The community this community is considered to be an agglomeration of.
Note that a main community will reference itself.
canton[R]

@return [SwissMatch::Canton]

The canton this community belongs to.
community_number[R]

@return [Integer]

A unique, never recycled identification number.
Also known as BFSNR.
name[R]

@return [String]

The official name of the community.
to_s[R]

@return [String]

The official name of the community.

Public Class Methods

new(community_number, name, canton, agglomeration) click to toggle source

@param [Integer] community_number

The identification number of the community, also known as BFSNR.

@param [String] name

The official name of the community

@param [SwissMatch::Canton] canton

The canton this community belongs to

@param [SwissMatch::Community] agglomeration

The community this community is considered to be an agglomeration of.
Note that a main community will reference itself.
# File lib/swissmatch/community.rb, line 38
def initialize(community_number, name, canton, agglomeration)
  @community_number = community_number
  @name             = name
  @canton           = canton
  @agglomeration    = agglomeration == :self ? self : agglomeration
end

Public Instance Methods

eql?(other) click to toggle source

@private @see Object#eql?

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

@private @see Object#hash

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

@return [String] @see Object#inspect

# File lib/swissmatch/community.rb, line 84
def inspect
  sprintf "\#<%s:%014x %s, BFSNR %d>", self.class, object_id, self, @community_number
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 community as a hash.
# File lib/swissmatch/community.rb, line 53
def to_hash(retain_references=false)
  if retain_references then
    canton        = @canton
    agglomeration = @agglomeration
  else
    canton        = @canton && @canton.license_tag
    agglomeration = @agglomeration && @agglomeration.community_number
  end

  {
    :community_number => @community_number,
    :name             => @name,
    :canton           => canton,
    :agglomeration    => agglomeration,
  }
end