Class: SwissMatch::Community
- Inherits:
-
Object
- Object
- SwissMatch::Community
- Defined in:
- lib/swissmatch/community.rb
Overview
Represents a swiss community. Swiss communities are identified by their community number (BFSNR).
Instance Attribute Summary collapse
-
#agglomeration ⇒ SwissMatch::Community
readonly
The community this community is considered to be an agglomeration of.
-
#canton ⇒ SwissMatch::Canton
readonly
The canton this community belongs to.
-
#community_number ⇒ Integer
readonly
A unique, never recycled identification number.
-
#name ⇒ String
(also: #to_s)
readonly
The official name of the community.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(community_number, name, canton, agglomeration) ⇒ Community
constructor
A new instance of Community.
- #inspect ⇒ String
-
#to_hash(retain_references = false) ⇒ Hash
All properties of the community as a hash.
Constructor Details
#initialize(community_number, name, canton, agglomeration) ⇒ Community
Returns a new instance of Community.
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
#agglomeration ⇒ SwissMatch::Community (readonly)
Returns 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 |
#canton ⇒ SwissMatch::Canton (readonly)
Returns The canton this community belongs to.
22 23 24 |
# File 'lib/swissmatch/community.rb', line 22 def canton @canton end |
#community_number ⇒ Integer (readonly)
Returns 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 |
#name ⇒ String (readonly) Also known as: to_s
Returns 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
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 |
#hash ⇒ Object
72 73 74 |
# File 'lib/swissmatch/community.rb', line 72 def hash [self.class, @community_number].hash end |
#inspect ⇒ String
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.
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 |