Class: KanjiMaster::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/kanji_master/address.rb

Overview

Address get data from Person.rb which access the data from ‘person.yml`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Address

Returns a new instance of Address.



21
22
23
24
25
26
27
28
29
# File 'lib/kanji_master/address.rb', line 21

def initialize(address)
  converter = Converter.new
  @zip_code       = address['zip_code']
  @name           = address['name']
  @katakana       = address['katakana']
  @kana           = @katakana
  @hiragana       = converter.hira(@katakana)
  @hira           = @hiragana
end

Instance Attribute Details

#hiraObject

Returns the value of attribute hira.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def hira
  @hira
end

#hiraganaObject

Returns the value of attribute hiragana.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def hiragana
  @hiragana
end

#kanaObject

Returns the value of attribute kana.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def kana
  @kana
end

#katakanaObject

Returns the value of attribute katakana.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def katakana
  @katakana
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def name
  @name
end

#zip_codeObject

Returns the value of attribute zip_code.



8
9
10
# File 'lib/kanji_master/address.rb', line 8

def zip_code
  @zip_code
end

Class Method Details

.dataObject



13
14
15
16
17
18
19
# File 'lib/kanji_master/address.rb', line 13

def self.data
  @data['persons']['person'].map do |h|
    new_hash = h.slice('address', 'address_kata', 'zip') if h['address'].present? && h['zip'].present?
    keys = { "address" => "name", "address_kata" => "katakana", "zip" => "zip_code" }
    Hash[new_hash.map{ |k, v| [keys[k], v]}]
  end
end