Class: JapanPostcoder::Address
- Inherits:
-
Object
- Object
- JapanPostcoder::Address
- Defined in:
- lib/japan_postcoder/address.rb
Overview
Class for Japanese Address Has attributes for postcode, prefecture, city, ward and district
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#district ⇒ Object
Returns the value of attribute district.
-
#postcode ⇒ Object
Returns the value of attribute postcode.
-
#prefecture ⇒ Object
Returns the value of attribute prefecture.
-
#ward ⇒ Object
Returns the value of attribute ward.
Instance Method Summary collapse
-
#initialize(postcode, prefecture, city, ward, district) ⇒ Address
constructor
Initialize the address with postcode, prefecture, city, ward and district.
-
#to_h ⇒ Object
Returns the full address as a hash.
-
#to_s(romaji: false) ⇒ Object
Returns the full address as a string.
Constructor Details
#initialize(postcode, prefecture, city, ward, district) ⇒ Address
Initialize the address with postcode, prefecture, city, ward and district
10 11 12 13 14 15 16 |
# File 'lib/japan_postcoder/address.rb', line 10 def initialize(postcode, prefecture, city, ward, district) @postcode = postcode @prefecture = prefecture @city = city @ward = ward @district = district end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
7 8 9 |
# File 'lib/japan_postcoder/address.rb', line 7 def city @city end |
#district ⇒ Object
Returns the value of attribute district.
7 8 9 |
# File 'lib/japan_postcoder/address.rb', line 7 def district @district end |
#postcode ⇒ Object
Returns the value of attribute postcode.
7 8 9 |
# File 'lib/japan_postcoder/address.rb', line 7 def postcode @postcode end |
#prefecture ⇒ Object
Returns the value of attribute prefecture.
7 8 9 |
# File 'lib/japan_postcoder/address.rb', line 7 def prefecture @prefecture end |
#ward ⇒ Object
Returns the value of attribute ward.
7 8 9 |
# File 'lib/japan_postcoder/address.rb', line 7 def ward @ward end |
Instance Method Details
#to_h ⇒ Object
Returns the full address as a hash
28 29 30 31 32 33 34 35 36 |
# File 'lib/japan_postcoder/address.rb', line 28 def to_h { postcode: @postcode, prefecture: @prefecture, city: @city, ward: @ward, district: @district } end |
#to_s(romaji: false) ⇒ Object
Returns the full address as a string
19 20 21 22 23 24 25 |
# File 'lib/japan_postcoder/address.rb', line 19 def to_s(romaji: false) if romaji "#{@prefecture} #{@city} #{@ward} #{@district}" else "#{@prefecture}#{@city}#{@ward}#{@district}" end end |