Class: JapaneseAddressParser::Models::Prefecture
- Inherits:
-
Object
- Object
- JapaneseAddressParser::Models::Prefecture
- Defined in:
- lib/japanese_address_parser/models/prefecture.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.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #cities ⇒ Object
-
#initialize(code:, name:, name_kana:, name_romaji:) ⇒ Prefecture
constructor
A new instance of Prefecture.
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
10 11 12 |
# File 'lib/japanese_address_parser/models/prefecture.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/prefecture.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/prefecture.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/prefecture.rb', line 10 def name_romaji @name_romaji end |
Class Method Details
.all ⇒ Object
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
#attributes ⇒ Object
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 |
#cities ⇒ Object
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 |