Class: Rubimas::Idol
- Inherits:
-
Object
- Object
- Rubimas::Idol
- Defined in:
- lib/rubimas/idol.rb
Constant Summary collapse
- @@cache =
{}
- @@id_cache =
{}
- @@config =
nil
Instance Attribute Summary collapse
-
#age ⇒ Object
readonly
Returns the value of attribute age.
-
#birthday ⇒ Object
readonly
Returns the value of attribute birthday.
-
#blood_type ⇒ Object
readonly
Returns the value of attribute blood_type.
-
#bust ⇒ Object
readonly
Returns the value of attribute bust.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#favorites ⇒ Object
readonly
Returns the value of attribute favorites.
-
#handedness ⇒ Object
readonly
Returns the value of attribute handedness.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#hip ⇒ Object
readonly
Returns the value of attribute hip.
-
#hobbies ⇒ Object
readonly
Returns the value of attribute hobbies.
-
#idol_id ⇒ Object
readonly
Returns the value of attribute idol_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_kana ⇒ Object
readonly
Returns the value of attribute name_kana.
-
#talents ⇒ Object
readonly
Returns the value of attribute talents.
-
#waist ⇒ Object
readonly
Returns the value of attribute waist.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
-
.config ⇒ Hash
Content of config/idols.yml.
- .find(idol_name) ⇒ Rubimas::Idol
- .find_by_id(idol_id) ⇒ Rubimas::Idol
- .names ⇒ Array<Symbol>
- .valid?(idol_name) ⇒ Boolean
Instance Method Summary collapse
-
#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
constructor
A new instance of Idol.
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
#age ⇒ Object (readonly)
Returns the value of attribute age.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def age @age end |
#birthday ⇒ Object (readonly)
Returns the value of attribute birthday.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def birthday @birthday end |
#blood_type ⇒ Object (readonly)
Returns the value of attribute blood_type.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def blood_type @blood_type end |
#bust ⇒ Object (readonly)
Returns the value of attribute bust.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def bust @bust end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def color @color end |
#favorites ⇒ Object (readonly)
Returns the value of attribute favorites.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def favorites @favorites end |
#handedness ⇒ Object (readonly)
Returns the value of attribute handedness.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def handedness @handedness end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def height @height end |
#hip ⇒ Object (readonly)
Returns the value of attribute hip.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def hip @hip end |
#hobbies ⇒ Object (readonly)
Returns the value of attribute hobbies.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def hobbies @hobbies end |
#idol_id ⇒ Object (readonly)
Returns the value of attribute idol_id.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def idol_id @idol_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def name @name end |
#name_kana ⇒ Object (readonly)
Returns the value of attribute name_kana.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def name_kana @name_kana end |
#talents ⇒ Object (readonly)
Returns the value of attribute talents.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def talents @talents end |
#waist ⇒ Object (readonly)
Returns the value of attribute waist.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def waist @waist end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
3 4 5 |
# File 'lib/rubimas/idol.rb', line 3 def weight @weight end |
Class Method Details
.config ⇒ Hash
Returns 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
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
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 |
.names ⇒ Array<Symbol>
40 41 42 |
# File 'lib/rubimas/idol.rb', line 40 def self.names config.keys end |
.valid?(idol_name) ⇒ Boolean
69 70 71 |
# File 'lib/rubimas/idol.rb', line 69 def self.valid?(idol_name) names.include?(idol_name) end |