Class: Jpzip::Town

Inherits:
Data
  • Object
show all
Defined in:
lib/jpzip/types.rb

Overview

Town corresponds to one element of ZipcodeEntry#towns.

Fields match the JSON shape served by the CDN (snake_case).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#kanaObject (readonly)

Returns the value of attribute kana

Returns:

  • (Object)

    the current value of kana



7
8
9
# File 'lib/jpzip/types.rb', line 7

def kana
  @kana
end

#noteObject (readonly)

Returns the value of attribute note

Returns:

  • (Object)

    the current value of note



7
8
9
# File 'lib/jpzip/types.rb', line 7

def note
  @note
end

#romaObject (readonly)

Returns the value of attribute roma

Returns:

  • (Object)

    the current value of roma



7
8
9
# File 'lib/jpzip/types.rb', line 7

def roma
  @roma
end

#townObject (readonly)

Returns the value of attribute town

Returns:

  • (Object)

    the current value of town



7
8
9
# File 'lib/jpzip/types.rb', line 7

def town
  @town
end

Class Method Details

.from_hash(h) ⇒ Object

Build a Town from a parsed JSON hash. Unknown keys are ignored so the SDK keeps working when the protocol grows new optional fields.



10
11
12
13
14
15
16
17
# File 'lib/jpzip/types.rb', line 10

def self.from_hash(h)
  new(
    town: h["town"] || "",
    kana: h["kana"] || "",
    roma: h["roma"] || "",
    note: h["note"]
  )
end

Instance Method Details

#to_hObject



19
20
21
22
23
# File 'lib/jpzip/types.rb', line 19

def to_h
  base = { town: town, kana: kana, roma: roma }
  base[:note] = note if note
  base
end