Class: JapaneseAddressParser::Data::SingleCity

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

Overview

SingleCity — api/ja.json の cities 要素(政令市の場合は区で区切られる)。 ::Data.define(先頭 :: は名前空間 JapaneseAddressParser::Data 内で トップレベル定数 ::Data を指すために必須)。

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city

Returns:

  • (Object)

    the current value of city



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def city
  @city
end

#city_kObject (readonly)

Returns the value of attribute city_k

Returns:

  • (Object)

    the current value of city_k



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def city_k
  @city_k
end

#city_rObject (readonly)

Returns the value of attribute city_r

Returns:

  • (Object)

    the current value of city_r



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def city_r
  @city_r
end

#codeObject (readonly)

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def code
  @code
end

#countyObject (readonly)

Returns the value of attribute county

Returns:

  • (Object)

    the current value of county



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def county
  @county
end

#county_kObject (readonly)

Returns the value of attribute county_k

Returns:

  • (Object)

    the current value of county_k



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def county_k
  @county_k
end

#county_rObject (readonly)

Returns the value of attribute county_r

Returns:

  • (Object)

    the current value of county_r



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def county_r
  @county_r
end

#pointObject (readonly)

Returns the value of attribute point

Returns:

  • (Object)

    the current value of point



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def point
  @point
end

#wardObject (readonly)

Returns the value of attribute ward

Returns:

  • (Object)

    the current value of ward



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def ward
  @ward
end

#ward_kObject (readonly)

Returns the value of attribute ward_k

Returns:

  • (Object)

    the current value of ward_k



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def ward_k
  @ward_k
end

#ward_rObject (readonly)

Returns the value of attribute ward_r

Returns:

  • (Object)

    the current value of ward_r



11
12
13
# File 'lib/japanese_address_parser/data/single_city.rb', line 11

def ward_r
  @ward_r
end

Class Method Details

.from_json(hash) ⇒ SingleCity

JSON(パース済み Hash・文字列キー)から VO を生成する Ruby 独自ヘルパ。

Parameters:

  • hash (Hash[String, untyped])

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/japanese_address_parser/data/single_city.rb', line 16

def self.from_json(hash)
  new(
    code: hash['code'],
    county: hash['county'],
    county_k: hash['county_k'],
    county_r: hash['county_r'],
    city: hash['city'],
    city_k: hash['city_k'],
    city_r: hash['city_r'],
    ward: hash['ward'],
    ward_k: hash['ward_k'],
    ward_r: hash['ward_r'],
    point: hash['point']
  )
end

.newinstance

Parameters:

  • code: (Integer)
  • county: (String, nil)
  • county_k: (String, nil)
  • county_r: (String, nil)
  • city: (String)
  • city_k: (String)
  • city_r: (String)
  • ward: (String, nil)
  • ward_k: (String, nil)
  • ward_r: (String, nil)
  • point: ([Float, Float])

Returns:

  • (instance)


19
# File 'sig/data.rbs', line 19

def self.new: (code: Integer, county: String?, county_k: String?, county_r: String?, city: String, city_k: String, city_r: String, ward: String?, ward_k: String?, ward_r: String?, point: [Float, Float]) -> instance

Instance Method Details

#city_nameString

JS: cityName(city) => ${city.county || ''}${city.city}${city.ward || ''} nil の補間は Ruby では空文字になるため || '' 相当。

Returns:

  • (String)


34
35
36
# File 'lib/japanese_address_parser/data/single_city.rb', line 34

def city_name
  "#{county}#{city}#{ward}"
end