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
11 12 13 14 15 16 17 |
# File 'lib/japan_postcoder/address.rb', line 11 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.
8 9 10 |
# File 'lib/japan_postcoder/address.rb', line 8 def city @city end |
#district ⇒ Object
Returns the value of attribute district.
8 9 10 |
# File 'lib/japan_postcoder/address.rb', line 8 def district @district end |
#postcode ⇒ Object
Returns the value of attribute postcode.
8 9 10 |
# File 'lib/japan_postcoder/address.rb', line 8 def postcode @postcode end |
#prefecture ⇒ Object
Returns the value of attribute prefecture.
8 9 10 |
# File 'lib/japan_postcoder/address.rb', line 8 def prefecture @prefecture end |
#ward ⇒ Object
Returns the value of attribute ward.
8 9 10 |
# File 'lib/japan_postcoder/address.rb', line 8 def ward @ward end |
Instance Method Details
#to_h ⇒ Object
Returns the full address as a hash
29 30 31 32 33 34 35 36 37 |
# File 'lib/japan_postcoder/address.rb', line 29 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
20 21 22 23 24 25 26 |
# File 'lib/japan_postcoder/address.rb', line 20 def to_s(romaji: false) if romaji "#{@prefecture} #{@city} #{@ward} #{@district}" else "#{@prefecture}#{@city}#{@ward}#{@district}" end end |