Class: JapaneseAddressParser::Town

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

Overview

町字のリッチ VO。name は machiAzaName(大字+丁目+小字)。point は代表点(NormalizeResultPoint, level 3)。 chome は "一丁目" 等の文字列、chome_n は 1 等の整数(JS SingleMachiAza が両方持つため両方公開する)。

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chomeObject (readonly)

Returns the value of attribute chome

Returns:

  • (Object)

    the current value of chome



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def chome
  @chome
end

#chome_nObject (readonly)

Returns the value of attribute chome_n

Returns:

  • (Object)

    the current value of chome_n



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def chome_n
  @chome_n
end

#koazaObject (readonly)

Returns the value of attribute koaza

Returns:

  • (Object)

    the current value of koaza



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def koaza
  @koaza
end

#machiaza_idObject (readonly)

Returns the value of attribute machiaza_id

Returns:

  • (Object)

    the current value of machiaza_id



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def machiaza_id
  @machiaza_id
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def name
  @name
end

#pointObject (readonly)

Returns the value of attribute point

Returns:

  • (Object)

    the current value of point



12
13
14
# File 'lib/japanese_address_parser/town.rb', line 12

def point
  @point
end

Class Method Details

.from_metadata(hash) ⇒ Town?

metadata.machi_aza(csv_ranges を除いた Hash・Symbol キー)から VO を作る。town 未判別なら nil。 point(level 3 代表点)は町字によっては存在しないため from_lng_lat が nil を返す。 name は Hash 入力のため SingleMachiAza#machi_aza_name を呼べない。式は同メソッド(JS: machiAzaName)と一致させる。

Parameters:

  • hash (Hash[Symbol, untyped], nil)

Returns:



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

def self.(hash)
  return if hash.nil?

  new(
    name: "#{hash[:oaza_cho]}#{hash[:chome]}#{hash[:koaza]}",
    machiaza_id: hash[:machiaza_id],
    chome: hash[:chome],
    chome_n: hash[:chome_n],
    koaza: hash[:koaza],
    point: NormalizeResultPoint.from_lng_lat(hash[:point], level: 3)
  )
end

.newinstance

Parameters:

  • name: (String)
  • machiaza_id: (String)
  • chome: (String, nil)
  • chome_n: (Integer, nil)
  • koaza: (String, nil)
  • point: (NormalizeResultPoint, nil)

Returns:

  • (instance)


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

def self.new: (name: String, machiaza_id: String, chome: String?, chome_n: Integer?, koaza: String?, point: NormalizeResultPoint?) -> instance

Instance Method Details

#to_hHash[Symbol, untyped]

緯度経度をネストも含めて Hash 化する Ruby 独自 API。

Returns:

  • (Hash[Symbol, untyped])


33
34
35
# File 'lib/japanese_address_parser/town.rb', line 33

def to_h
  { name:, machiaza_id:, chome:, chome_n:, koaza:, point: point&.to_h }
end