Class: SwissMatch::Community

Inherits:
Object
  • Object
show all
Defined in:
lib/swissmatch/community.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(community_number, name, canton, agglomeration) ⇒ Community

Returns a new instance of Community.

Parameters:

  • community_number (Integer)

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

  • name (String)

    The official name of the community

  • canton (SwissMatch::Canton)

    The canton this community belongs to

  • agglomeration (SwissMatch::Community)

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



38
39
40
41
42
43
# 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

Instance Attribute Details

#agglomerationSwissMatch::Community (readonly)

Returns The community this community is considered to be an agglomeration of. Note that a main community will reference itself.

Returns:

  • (SwissMatch::Community)

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



27
28
29
# File 'lib/swissmatch/community.rb', line 27

def agglomeration
  @agglomeration
end

#cantonSwissMatch::Canton (readonly)

Returns The canton this community belongs to.

Returns:



22
23
24
# File 'lib/swissmatch/community.rb', line 22

def canton
  @canton
end

#community_numberInteger (readonly)

Returns A unique, never recycled identification number. Also known as BFSNR.

Returns:

  • (Integer)

    A unique, never recycled identification number. Also known as BFSNR.



14
15
16
# File 'lib/swissmatch/community.rb', line 14

def community_number
  @community_number
end

#nameString (readonly) Also known as: to_s

Returns The official name of the community.

Returns:

  • (String)

    The official name of the community.



18
19
20
# File 'lib/swissmatch/community.rb', line 18

def name
  @name
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?


78
79
80
# File 'lib/swissmatch/community.rb', line 78

def eql?(other)
  self.class.eql?(other.class) && @community_number.eql?(other.community_number)
end

#hashObject

See Also:

  • Object#hash


72
73
74
# File 'lib/swissmatch/community.rb', line 72

def hash
  [self.class, @community_number].hash
end

#inspectString

Returns:

  • (String)

See Also:

  • Object#inspect


84
85
86
# 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) ⇒ Hash

Returns All properties of the community as a hash.

Parameters:

  • retain_references (Boolean) (defaults to: false)

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

Returns:

  • (Hash)

    All properties of the community as a hash.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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