Class: Rubicure::Girl

Inherits:
Hash
  • Object
show all
Includes:
Hashie::Extensions::MethodAccess
Defined in:
lib/rubicure/girl.rb

Overview

Precure girl (ex. Cure Peace, Cure Rosetta, Cure Honey)

this is record of "config/girls/*.yml"

Constant Summary collapse

ATTRIBUTES =
[
  :girl_name,
  :human_name,
  :human_full_name,
  :human_real_name,
  :precure_name,
  :cast_name,
  :color,
  :created_date,
  :birthday,
  :transform_message,
  :extra_names,
  :attack_messages,
  :transform_calls,
  :random_transform_words,
].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



298
299
300
301
302
# File 'lib/rubicure/girl.rb', line 298

def method_missing(method_name, *args)
  return super unless respond_to_missing?(method_name, false)

  transform!(*args)
end

Class Attribute Details

.sleep_sec ⇒ Object



251
252
253
# File 'lib/rubicure/girl.rb', line 251

def sleep_sec
  @sleep_sec ||= 1
end

Class Method Details

.colors ⇒ Array<Symbol>

return defined colors

Returns:

  • (Array<Symbol>)


257
258
259
260
261
262
# File 'lib/rubicure/girl.rb', line 257

def colors
  unless @colors
    @colors = config.values.each_with_object([]) {|girl, colors| colors << girl[:color].to_sym }.uniq.sort
  end
  @colors
end

.config ⇒ Hash

Returns content of config/girls/*.yml.

Returns:

  • (Hash) —

    content of config/girls/*.yml



231
232
233
234
235
236
# File 'lib/rubicure/girl.rb', line 231

def config
  unless @config
    @config = SengiriYaml.load_dir("#{File.dirname(__FILE__)}/../../config/girls", permitted_classes: [Date], aliases: true).deep_symbolize_keys
  end
  @config
end

.find(girl_name) ⇒ Rubicure::Girl

Parameters:

  • girl_name (Symbol)

Returns:



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/rubicure/girl.rb', line 206

def find(girl_name)
  raise "unknown girl: #{girl_name}" unless valid?(girl_name)

  @cache ||= {}
  unless @cache[girl_name]
    girl_config = config[girl_name] || {}
    @cache[girl_name] = Rubicure::Girl[girl_config]
  end

  @cache[girl_name]
end

.names ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


219
220
221
# File 'lib/rubicure/girl.rb', line 219

def names
  config.keys
end

.reload_config! ⇒ Hash

Returns content of config/precure.yml.

Returns:

  • (Hash) —

    content of config/precure.yml



239
240
241
242
243
244
# File 'lib/rubicure/girl.rb', line 239

def reload_config!
  @cache = {}
  @config = nil
  @colors = nil
  config
end

.uniq_names ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


224
225
226
227
228
# File 'lib/rubicure/girl.rb', line 224

def uniq_names
  config.each_with_object([]) do |(name, girl), uniq_names|
    uniq_names << name unless uniq_names.any? {|uniq_name| config[uniq_name][:precure_name] == girl[:precure_name] }
  end
end

.valid?(girl_name) ⇒ Boolean

Parameters:

  • girl_name (Symbol)

Returns:

  • (Boolean)


247
248
249
# File 'lib/rubicure/girl.rb', line 247

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

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rubicure/girl.rb', line 42

def ==(other)
  other.is_a?(self.class) && self.human_name == other.human_name
end

#attack! ⇒ Object

Attack to enemy

Examples:

yayoi = Cure.peace
yayoi.transform!

yayoi.attack!

# プリキュア!ピースサンダー!!

Raises:



124
125
126
127
128
129
130
# File 'lib/rubicure/girl.rb', line 124

def attack!
  raise RequireTransformError, "require transform" if current_attack_message.blank?

   current_attack_message

  current_attack_message
end

#birthday?(date = Date.today) ⇒ Boolean

Whether date is her birthday

Examples:

Cure.twinkle.birthday?(Date.parse("2015-9-12"))
#=> true

Parameters:

  • date (Date) (defaults to: Date.today)

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
149
150
# File 'lib/rubicure/girl.rb', line 141

def birthday?(date = Date.today)
  return false unless have_birthday?

  # NOTE: birthday is "mm/dd"
  month, day = birthday.split("/")

  birthday_date = Date.new(date.year, month.to_i, day.to_i)

  birthday_date == date
end

#current_state ⇒ Integer

Returns:

  • (Integer)


30
31
32
# File 'lib/rubicure/girl.rb', line 30

def current_state
  @current_state ||= 0
end

#full_name ⇒ String

returns human_full_name or human_name

Returns:

  • (String)


170
171
172
# File 'lib/rubicure/girl.rb', line 170

def full_name
  human_full_name.presence || human_name
end

#have_birthday? ⇒ Boolean Also known as: has_birthday?

Whether she has birthday

Examples:

Cure.peace.have_birthday?
#=> false

Cure.twinkle.has_birthday?
#=> true

Returns:

  • (Boolean)


162
163
164
# File 'lib/rubicure/girl.rb', line 162

def have_birthday? # rubocop:disable Naming/PredicateName
  has_key?(:birthday)
end

#heisei? ⇒ Boolean

Whether Heisei precure

Returns:

  • (Boolean)


182
183
184
# File 'lib/rubicure/girl.rb', line 182

def heisei?
  created_date.heisei?
end

#humanize! ⇒ Object

Rollback to human

Examples:

yayoi = Cure.peace
yayoi.transform!
yayoi.name
#=> "キュアピース"

yayoi.humanize!
yayoi.name
#=> "黄瀬やよい"


107
108
109
110
111
# File 'lib/rubicure/girl.rb', line 107

def humanize!
  @current_state = 0
  @current_transform_style = nil
  self
end

#name ⇒ String Also known as: to_s

Returns name of current form.

Returns:

  • (String) —

    name of current form



47
48
49
# File 'lib/rubicure/girl.rb', line 47

def name
  state_names[current_state]
end

#real_name ⇒ String

returns human_real_name or human_name

Returns:

  • (String)


177
178
179
# File 'lib/rubicure/girl.rb', line 177

def real_name
  human_real_name.presence || human_name
end

#reiwa? ⇒ Boolean

Whether Reiwa precure

Returns:

  • (Boolean)


187
188
189
# File 'lib/rubicure/girl.rb', line 187

def reiwa?
  created_date.reiwa?
end

#state_names ⇒ Array<String>

Returns:

  • (Array<String>)


35
36
37
38
39
# File 'lib/rubicure/girl.rb', line 35

def state_names
  state_names = [human_name, precure_name]
  state_names += Array.wrap(extra_names) if respond_to?(:extra_names)
  state_names
end

#transform!(style = nil) ⇒ Rubicure::Girl

human -> precure ( -> extra forms ) -> human ...

Examples:

yayoi = Cure.peace

yayoi.name
#=> "黄瀬やよい"

yayoi.transform!

# (レディ?)
# プリキュア・スマイルチャージ!
# (ゴー!ゴー!レッツ・ゴー!ピース!!)
# ピカピカピカリンジャンケンポン! キュアピース!
# 5つの光が導く未来!
# 輝け!スマイルプリキュア!

yayoi.name
#=> "キュアピース"

Parameters:

  • style (Symbol) (defaults to: nil)

Returns:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rubicure/girl.rb', line 75

def transform!(style = nil)
  if style
    raise "Unknown style: #{style}" unless has_transform_style?(style)

    @current_transform_style = style
  end

  state = inc_current_state

  message =
    if random_transform_words && !random_transform_words.empty?
      random_transform_word = random_transform_words.sample
      transform_message.gsub("${random_transform_word}", random_transform_word)
    else
      transform_message
    end
   message if state == 1

  self
end