Class: Rubimas::Idol

Inherits:
Object
  • Object
show all
Defined in:
lib/rubimas/idol.rb

Constant Summary collapse

@@cache =
{}
@@id_cache =
{}
@@config =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(idol_id: nil, name: nil, name_kana: nil, age: nil, height: nil, weight: nil, bust: nil, waist: nil, hip: nil, birthday: nil, blood_type: nil, handedness: nil, hobbies: [], talents: [], favorites: [], color: nil) ⇒ Idol

Returns a new instance of Idol.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubimas/idol.rb', line 9

def initialize(idol_id: nil, name: nil, name_kana: nil, age: nil, height: nil, weight: nil,
               bust: nil, waist: nil, hip: nil, birthday: nil, blood_type: nil, handedness: nil,
               hobbies: [], talents: [], favorites: [], color: nil)
  @idol_id          = idol_id
  @name             = name
  @name_kana        = name_kana
  @age              = age
  @height           = height
  @weight           = weight
  @bust             = bust
  @waist            = waist
  @hip              = hip
  @birthday         = birthday
  @blood_type       = blood_type
  @handedness       = handedness
  @hobbies          = hobbies
  @talents          = talents
  @favorites        = favorites
  @color            = color
end

Instance Attribute Details

#ageObject (readonly)

Returns the value of attribute age.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def age
  @age
end

#birthdayObject (readonly)

Returns the value of attribute birthday.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def birthday
  @birthday
end

#blood_typeObject (readonly)

Returns the value of attribute blood_type.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def blood_type
  @blood_type
end

#bustObject (readonly)

Returns the value of attribute bust.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def bust
  @bust
end

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def color
  @color
end

#favoritesObject (readonly)

Returns the value of attribute favorites.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def favorites
  @favorites
end

#handednessObject (readonly)

Returns the value of attribute handedness.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def handedness
  @handedness
end

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def height
  @height
end

#hipObject (readonly)

Returns the value of attribute hip.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def hip
  @hip
end

#hobbiesObject (readonly)

Returns the value of attribute hobbies.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def hobbies
  @hobbies
end

#idol_idObject (readonly)

Returns the value of attribute idol_id.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def idol_id
  @idol_id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def name
  @name
end

#name_kanaObject (readonly)

Returns the value of attribute name_kana.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def name_kana
  @name_kana
end

#talentsObject (readonly)

Returns the value of attribute talents.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def talents
  @talents
end

#waistObject (readonly)

Returns the value of attribute waist.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def waist
  @waist
end

#weightObject (readonly)

Returns the value of attribute weight.



3
4
5
# File 'lib/rubimas/idol.rb', line 3

def weight
  @weight
end

Class Method Details

.configHash

Returns content of config/idols.yml.

Returns:

  • (Hash)

    content of config/idols.yml



31
32
33
34
35
36
37
# File 'lib/rubimas/idol.rb', line 31

def self.config
  unless @@config
    config_file = "#{File.dirname(__FILE__)}/../../config/idols.yml"
    @@config = YAML.load_file(config_file).deep_symbolize_keys
  end
  @@config
end

.find(idol_name) ⇒ Rubimas::Idol

Parameters:

  • idol_name (Symbol)

Returns:



46
47
48
49
50
51
52
53
54
55
# File 'lib/rubimas/idol.rb', line 46

def self.find(idol_name)
  raise "unknown idol: #{idol_name}" unless valid?(idol_name)

  unless @@cache[idol_name]
    idol_config = config[idol_name] || {}
    @@cache[idol_name] = Rubimas::Idol.new(idol_config)
  end

  @@cache[idol_name]
end

.find_by_id(idol_id) ⇒ Rubimas::Idol

Parameters:

Returns:



59
60
61
62
63
64
65
66
# File 'lib/rubimas/idol.rb', line 59

def self.find_by_id(idol_id)
  unless @@id_cache[idol_id]
    idol_config = config.select { |k, v| v[:idol_id] == idol_id }.values.first
    @@id_cache[idol_id] = Rubimas::Idol.new(idol_config)
  end

  @@id_cache[idol_id]
end

.namesArray<Symbol>

Returns:

  • (Array<Symbol>)


40
41
42
# File 'lib/rubimas/idol.rb', line 40

def self.names
  config.keys
end

.valid?(idol_name) ⇒ Boolean

Parameters:

  • idol_name (Symbol)

Returns:

  • (Boolean)


69
70
71
# File 'lib/rubimas/idol.rb', line 69

def self.valid?(idol_name)
  names.include?(idol_name)
end