Class: SwissMatch::District
- Inherits:
-
Object
- Object
- SwissMatch::District
- Defined in:
- lib/swissmatch/district.rb
Overview
Represents a swiss district.
Instance Attribute Summary collapse
-
#canton ⇒ Object
readonly
Returns the value of attribute canton.
-
#communities ⇒ SwissMatch::Communities
readonly
The political communities belonging to this district.
-
#district_number ⇒ String
readonly
The district number.
-
#name ⇒ String
(also: #to_s)
readonly
The name of the district.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(district_number, name, canton, communities) ⇒ District
constructor
A new instance of District.
- #inspect ⇒ String
-
#to_hash(retain_references = false) ⇒ Hash
All properties of the district as a hash.
Constructor Details
#initialize(district_number, name, canton, communities) ⇒ District
Returns a new instance of 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
#canton ⇒ Object (readonly)
Returns the value of attribute canton.
22 23 24 |
# File 'lib/swissmatch/district.rb', line 22 def canton @canton end |
#communities ⇒ SwissMatch::Communities (readonly)
Returns The political communities belonging to this district.
20 21 22 |
# File 'lib/swissmatch/district.rb', line 20 def communities @communities end |
#district_number ⇒ String (readonly)
Returns The district number.
12 13 14 |
# File 'lib/swissmatch/district.rb', line 12 def district_number @district_number end |
#name ⇒ String (readonly) Also known as: to_s
Returns 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
72 73 74 |
# File 'lib/swissmatch/district.rb', line 72 def eql?(other) self.class.eql?(other.class) && @number.eql?(other.number) end |
#hash ⇒ Object
66 67 68 |
# File 'lib/swissmatch/district.rb', line 66 def hash [self.class, @number].hash end |
#inspect ⇒ String
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.
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 |