Class: KanjiMaster::Name

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

Overview

Name 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(name) ⇒ Name

Returns a new instance of Name.



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

def initialize(name)
  converter = Converter.new
  @full_name       = name['full_name']
  @first_name      = @full_name.split[1]
  @last_name       = @full_name.split[0]
  @katakana        = name['katakana']
  @kana            = @katakana
  @hiragana        = converter.hira(@katakana)
  @hira            = @hiragana
end

Instance Attribute Details

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#hiraObject

Returns the value of attribute hira.



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

def hira
  @hira
end

#hiraganaObject

Returns the value of attribute hiragana.



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

def hiragana
  @hiragana
end

#kanaObject

Returns the value of attribute kana.



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

def kana
  @kana
end

#katakanaObject

Returns the value of attribute katakana.



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

def katakana
  @katakana
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#zip_codeObject

Returns the value of attribute zip_code.



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

def zip_code
  @zip_code
end

Class Method Details

.dataObject



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

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