Class: Rubimas::Idol

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

Defined Under Namespace

Classes: Name, UnknownIdolError

Constant Summary collapse

@@config =
nil
@@all_idols =
nil
@@theaterdays =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ 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
29
# File 'lib/rubimas/idol.rb', line 9

def initialize(**args)
  @idol_id          = args[:idol_id]
  @key              = args[:key]
  @idol_type        = args[:idol_type]
  @idol_image       = args[:idol_image]
  @name             = Name.new(args[:name])
  @age              = args[:age]
  @height           = args[:height]
  @weight           = args[:weight]
  @bust             = args[:bust]
  @waist            = args[:waist]
  @hip              = args[:hip]
  @birthday         = args[:birthday]
  @blood_type       = args[:blood_type]
  @handedness       = args[:handedness]
  @hobbies          = args[:hobbies]
  @talents          = args[:talents]
  @favorites        = args[:favorites]
  @color            = args[:color]
  @cv               = args[:cv]
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

#cvObject (readonly)

Returns the value of attribute cv.



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

def cv
  @cv
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) Also known as: id

Returns the value of attribute idol_id.



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

def idol_id
  @idol_id
end

#idol_imageObject (readonly)

Returns the value of attribute idol_image.



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

def idol_image
  @idol_image
end

#idol_typeObject (readonly)

Returns the value of attribute idol_type.



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

def idol_type
  @idol_type
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
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

.allObject Also known as: all_idols



54
55
56
# File 'lib/rubimas/idol.rb', line 54

def all
  @@all_idols ||= config.map { |key, prof| prof[:key] = key; new(prof) }.sort_by { |idol| idol.id }
end

.config(force: false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/rubimas/idol.rb', line 33

def config(force: false)
  unless @@config && !force
    regexp = @@theaterdays ? '*' : '{[0-4][0-9],50}*'
    @@config = Dir.glob("#{File.dirname(__FILE__)}/../../config/idols/#{regexp}.yml").each_with_object({}) do |file, idols|
      idols.merge!(YAML.load_file(file))
    end.deep_symbolize_keys
    @@all_idols = nil
  end
  @@config
end

.find(idol_id) ⇒ Object Also known as: find_by_id



59
60
61
# File 'lib/rubimas/idol.rb', line 59

def find(idol_id)
  all_idols.find { |idol| idol.id == idol_id }
end

.find_by_name(idol_name) ⇒ Object



64
65
66
# File 'lib/rubimas/idol.rb', line 64

def find_by_name(idol_name)
  all_idols.find { |idol| [idol.key, idol.name].include?(idol_name) } || (raise UnknownIdolError, "unknown idol: #{idol_name}")
end

.namesObject



50
51
52
# File 'lib/rubimas/idol.rb', line 50

def names
  config.keys
end

.theaterdays!Object



44
45
46
47
48
# File 'lib/rubimas/idol.rb', line 44

def theaterdays!
  @@theaterdays = true
  config(force: true)
  true
end

.valid?(idol_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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