Class: JapaneseAddressParser::Models::Prefecture

Inherits:
Object
  • Object
show all
Defined in:
lib/japanese_address_parser/models/prefecture.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, name:, name_kana:, name_romaji:) ⇒ Prefecture

Returns a new instance of Prefecture.



19
20
21
22
23
24
# File 'lib/japanese_address_parser/models/prefecture.rb', line 19

def initialize(code:, name:, name_kana:, name_romaji:)
  @code = code
  @name = name
  @name_kana = name_kana
  @name_romaji = name_romaji
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/japanese_address_parser/models/prefecture.rb', line 10

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/japanese_address_parser/models/prefecture.rb', line 10

def name
  @name
end

#name_kanaObject (readonly)

Returns the value of attribute name_kana.



10
11
12
# File 'lib/japanese_address_parser/models/prefecture.rb', line 10

def name_kana
  @name_kana
end

#name_romajiObject (readonly)

Returns the value of attribute name_romaji.



10
11
12
# File 'lib/japanese_address_parser/models/prefecture.rb', line 10

def name_romaji
  @name_romaji
end

Class Method Details

.allObject



12
13
14
15
16
17
# File 'lib/japanese_address_parser/models/prefecture.rb', line 12

def self.all
  filepath = Pathname(__FILE__).dirname.join('../data/prefectures.csv')
  ::CSV.table(filepath, converters: nil).map do |prefecture|
    new(code: prefecture[:code], name: prefecture[:name], name_kana: prefecture[:name_kana], name_romaji: prefecture[:name_romaji])
  end
end

Instance Method Details

#attributesObject



26
27
28
# File 'lib/japanese_address_parser/models/prefecture.rb', line 26

def attributes
  { code: code, name: name, name_kana: name_kana, name_romaji: name_romaji }
end

#citiesObject



30
31
32
33
34
35
# File 'lib/japanese_address_parser/models/prefecture.rb', line 30

def cities
  filepath = Pathname(__FILE__).dirname.join("../data/#{code}.csv")
  ::CSV.table(filepath, converters: nil).map do |city|
    ::JapaneseAddressParser::Models::City.new(code: city[:code], prefecture_code: city[:prefecture_code], name: city[:name], name_kana: city[:name_kana], name_romaji: city[:name_romaji])
  end
end