Class: JapaneseAddressParser::Address

Inherits:
Data
  • Object
show all
Defined in:
lib/japanese_address_parser/address.rb,
lib/japanese_address_parser/address.rb,
sig/address.rbs

Overview

正規化結果の公開 VO。prefecture/city/town は未判別なら nil(JS 同様、未マッチは失敗ではない)。 metadata は VO に昇格しない生データ(rsdt/chiban 等)の逃がし道(working_agreement §1-3)。

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addrObject (readonly)

Returns the value of attribute addr

Returns:

  • (Object)

    the current value of addr



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def addr
  @addr
end

#cityObject (readonly)

Returns the value of attribute city

Returns:

  • (Object)

    the current value of city



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def city
  @city
end

#full_addressObject (readonly)

Returns the value of attribute full_address

Returns:

  • (Object)

    the current value of full_address



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def full_address
  @full_address
end

#levelObject (readonly)

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def level
  @level
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def 
  @metadata
end

#otherObject (readonly)

Returns the value of attribute other

Returns:

  • (Object)

    the current value of other



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def other
  @other
end

#pointObject (readonly)

Returns the value of attribute point

Returns:

  • (Object)

    the current value of point



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def point
  @point
end

#prefectureObject (readonly)

Returns the value of attribute prefecture

Returns:

  • (Object)

    the current value of prefecture



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def prefecture
  @prefecture
end

#townObject (readonly)

Returns the value of attribute town

Returns:

  • (Object)

    the current value of town



14
15
16
# File 'lib/japanese_address_parser/address.rb', line 14

def town
  @town
end

Class Method Details

.from_normalize_result(result) ⇒ Address

内部 NormalizeResult から公開 Address を組み立てる。

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/japanese_address_parser/address.rb', line 19

def self.from_normalize_result(result)
   = result.
  new(
    full_address: .input,
    prefecture: Prefecture.(.prefecture),
    city: City.(.city),
    town: Town.(.machi_aza),
    addr: result.addr,
    other: result.other,
    point: result.point,
    level: result.level,
    metadata:
  )
end

.newinstance

Parameters:

Returns:

  • (instance)


55
# File 'sig/address.rbs', line 55

def self.new: (full_address: String, prefecture: Prefecture?, city: City?, town: Town?, addr: String?, other: String, point: NormalizeResultPoint?, level: Integer, metadata: NormalizeResultMetadata) -> instance

Instance Method Details

#to_hHash[Symbol, untyped]

ネストした VO・座標も含めて Hash 化する Ruby 独自 API。metadata は生データの逃がし道として shallow に Hash 化する(内部の SingleCity 等は VO のまま)。

Returns:

  • (Hash[Symbol, untyped])


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/japanese_address_parser/address.rb', line 36

def to_h
  {
    full_address:,
    prefecture: prefecture&.to_h,
    city: city&.to_h,
    town: town&.to_h,
    addr:,
    other:,
    point: point&.to_h,
    level:,
    metadata: .to_h
  }
end