Class: JapaneseAddressParser::Models::City
- Inherits:
-
Object
- Object
- JapaneseAddressParser::Models::City
- Defined in:
- lib/japanese_address_parser/models/city.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_kana ⇒ Object
readonly
Returns the value of attribute name_kana.
-
#name_romaji ⇒ Object
readonly
Returns the value of attribute name_romaji.
-
#prefecture_code ⇒ Object
readonly
Returns the value of attribute prefecture_code.
Instance Method Summary collapse
- #attributes ⇒ Object
- #formatted_code ⇒ Object
-
#initialize(code:, prefecture_code:, name:, name_kana:, name_romaji:) ⇒ City
constructor
A new instance of City.
- #prefecture ⇒ Object
- #towns ⇒ Object
Constructor Details
#initialize(code:, prefecture_code:, name:, name_kana:, name_romaji:) ⇒ City
Returns a new instance of City.
12 13 14 15 16 17 18 |
# File 'lib/japanese_address_parser/models/city.rb', line 12 def initialize(code:, prefecture_code:, name:, name_kana:, name_romaji:) @code = code @prefecture_code = prefecture_code @name = name @name_kana = name_kana @name_romaji = name_romaji end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
10 11 12 |
# File 'lib/japanese_address_parser/models/city.rb', line 10 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/japanese_address_parser/models/city.rb', line 10 def name @name end |
#name_kana ⇒ Object (readonly)
Returns the value of attribute name_kana.
10 11 12 |
# File 'lib/japanese_address_parser/models/city.rb', line 10 def name_kana @name_kana end |
#name_romaji ⇒ Object (readonly)
Returns the value of attribute name_romaji.
10 11 12 |
# File 'lib/japanese_address_parser/models/city.rb', line 10 def name_romaji @name_romaji end |
#prefecture_code ⇒ Object (readonly)
Returns the value of attribute prefecture_code.
10 11 12 |
# File 'lib/japanese_address_parser/models/city.rb', line 10 def prefecture_code @prefecture_code end |
Instance Method Details
#attributes ⇒ Object
24 25 26 |
# File 'lib/japanese_address_parser/models/city.rb', line 24 def attributes { code: code, formatted_code: formatted_code, prefecture_code: prefecture_code, name: name, name_kana: name_kana, name_romaji: name_romaji } end |
#formatted_code ⇒ Object
20 21 22 |
# File 'lib/japanese_address_parser/models/city.rb', line 20 def formatted_code code.nil? ? 'UNKNOWN' : code end |
#prefecture ⇒ Object
28 29 30 |
# File 'lib/japanese_address_parser/models/city.rb', line 28 def prefecture ::JapaneseAddressParser::Models::Prefecture.all.find { |prefecture| prefecture.code == prefecture_code } end |
#towns ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/japanese_address_parser/models/city.rb', line 32 def towns filepath = Pathname(__FILE__).dirname.join("../data/#{prefecture_code}-#{formatted_code}.csv") ::CSV.table(filepath, converters: nil).map do |town| ::JapaneseAddressParser::Models::Town.new( name: town[:name], name_kana: town[:name_kana], name_romaji: town[:name_romaji], nickname: town[:nickname], latitude: town[:latitude], longitude: town[:longitude] ) end end |