Class: JapanPostcoder::Address

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/japan_postcoder/address.rb', line 7

def city
  @city
end

#districtObject

Returns the value of attribute district.



7
8
9
# File 'lib/japan_postcoder/address.rb', line 7

def district
  @district
end

#postcodeObject

Returns the value of attribute postcode.



7
8
9
# File 'lib/japan_postcoder/address.rb', line 7

def postcode
  @postcode
end

#prefectureObject

Returns the value of attribute prefecture.



7
8
9
# File 'lib/japan_postcoder/address.rb', line 7

def prefecture
  @prefecture
end

#wardObject

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_hObject

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