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



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

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#districtObject

Returns the value of attribute district.



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

def district
  @district
end

#postcodeObject

Returns the value of attribute postcode.



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

def postcode
  @postcode
end

#prefectureObject

Returns the value of attribute prefecture.



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

def prefecture
  @prefecture
end

#wardObject

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_hObject

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