Class: SwissMatch::District

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

Overview

Represents a swiss district.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(district_number, name, canton, communities) ⇒ District

Returns a new instance of District.

Parameters:

  • district_number (String)

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

  • name (String)

    The official name of the district.

  • canton (SwissMatch::Canton)

    The canton this district belongs to

  • communities (SwissMatch::Communities)

    The communities belonging to this district


32
33
34
35
36
37
# 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

Instance Attribute Details

#cantonObject (readonly)

Returns the value of attribute canton


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

def canton
  @canton
end

#communitiesSwissMatch::Communities (readonly)

Returns The political communities belonging to this district.

Returns:


20
21
22
# File 'lib/swissmatch/district.rb', line 20

def communities
  @communities
end

#district_numberString (readonly)

Returns The district number.

Returns:

  • (String)

    The district number.


12
13
14
# File 'lib/swissmatch/district.rb', line 12

def district_number
  @district_number
end

#nameString (readonly) Also known as: to_s

Returns The name of the district.

Returns:

  • (String)

    The name of the district.


16
17
18
# File 'lib/swissmatch/district.rb', line 16

def name
  @name
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Object#eql?

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

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

#hashObject

See Also:

  • Object#hash

66
67
68
# File 'lib/swissmatch/district.rb', line 66

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

#inspectString

Returns:

  • (String)

See Also:

  • Object#inspect

78
79
80
# 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) ⇒ Hash

Returns All properties of the district 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 district as a hash.


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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