class ShinyColors::Idol

Attributes

age[R]
birthday[R]
birthplace[R]
blood_type[R]
cv[R]
dominant_hand[R]
hobby[R]
key_name[R]
name[R]
nickname_kana[R]
nickname_key[R]
special_skills[R]
zodiac_sign[R]

Public Class Methods

all() click to toggle source
# File lib/shinycolors/idol.rb, line 32
def all
  data.map do |key, values|
    values[:key_name] = key
    new(**values)
  end
end
find(name) click to toggle source
# File lib/shinycolors/idol.rb, line 49
def find(name)
  h = data[name]
  raise(NotFoundError) if h.nil?

  h[:key_name] = name
  new(**h)
end
names() click to toggle source
# File lib/shinycolors/idol.rb, line 39
def names
  data.keys
end
new(name:, cv:, age:, blood_type:, birthday:, zodiac_sign:, dominant_hand:, birthplace:, hobby:, special_skills:, nickname_key:, nickname_kana:, key_name:) click to toggle source
# File lib/shinycolors/idol.rb, line 11
def initialize(name:, cv:, age:, blood_type:, birthday:, zodiac_sign:, dominant_hand:,
               birthplace:, hobby:, special_skills:, nickname_key:, nickname_kana:, key_name:)
  @name = name
  @cv = cv
  @age = age
  @blood_type = blood_type
  @birthday = birthday
  @zodiac_sign = zodiac_sign
  @dominant_hand = dominant_hand
  @birthplace = birthplace
  @hobby = hobby
  @special_skills = special_skills
  @nickname_key = nickname_key
  @nickname_kana = nickname_kana
  @key_name = key_name
end
nicknames() click to toggle source
# File lib/shinycolors/idol.rb, line 43
def nicknames
  data.each_with_object({}) do |(fullname, values), result|
    values[:nickname_key]&.each { |nickname| result.merge!({ nickname => fullname }) }
  end
end
sample() click to toggle source
# File lib/shinycolors/idol.rb, line 57
def sample
  all.sample
end

Private Class Methods

data() click to toggle source
# File lib/shinycolors/idol.rb, line 63
def data
  return @data unless @data.nil?

  @data = YAML.load_file('./data/idol.yml').each_with_object({}) do |(_, values), result|
    result.merge!(values['idols'])
  end.deep_symbolize_keys!
end

Public Instance Methods

==(other) click to toggle source
# File lib/shinycolors/idol.rb, line 72
def ==(other)
  key_name == other.key_name
end
display() click to toggle source

TODO: to module.

# File lib/shinycolors/idol.rb, line 87
    def display
      puts <<~TEXT
          名前: #{name}
            CV: #{cv}
          年齢: #{age}
        血液型: #{blood_type}
        誕生日: #{birthday}
          星座: #{zodiac_sign}
        利き手: #{dominant_hand}
        出身地: #{birthplace}
          趣味: #{hobby}
          特技: #{special_skills}
      TEXT
    end
nickname() click to toggle source
# File lib/shinycolors/idol.rb, line 76
def nickname
  nickname_kana
end
unit_name() click to toggle source
# File lib/shinycolors/idol.rb, line 80
def unit_name
  Unit.all.select do |unit|
    unit.idols.include?(self)
  end.first.name
end