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,
  :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)



290
291
292
293
294
# File 'lib/rubicure/girl.rb', line 290

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

  transform!(*args)
end

Class Attribute Details

.sleep_secObject



243
244
245
# File 'lib/rubicure/girl.rb', line 243

def sleep_sec
  @sleep_sec ||= 1
end

Class Method Details

.colorsArray<Symbol>

return defined colors

Returns:

  • (Array<Symbol>)


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

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

.configHash

Returns content of config/girls/*.yml.

Returns:

  • (Hash)

    content of config/girls/*.yml



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

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:



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rubicure/girl.rb', line 198

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

.namesArray<Symbol>

Returns:

  • (Array<Symbol>)


211
212
213
# File 'lib/rubicure/girl.rb', line 211

def names
  config.keys
end

.reload_config!Hash

Returns content of config/precure.yml.

Returns:

  • (Hash)

    content of config/precure.yml



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

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

.uniq_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


216
217
218
219
220
# File 'lib/rubicure/girl.rb', line 216

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)


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

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

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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:



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

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)


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

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_stateInteger

Returns:

  • (Integer)


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

def current_state
  @current_state ||= 0
end

#full_nameString

returns human_full_name or human_name

Returns:

  • (String)


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

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)


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

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

#heisei?Boolean

Whether Heisei precure

Returns:

  • (Boolean)


174
175
176
# File 'lib/rubicure/girl.rb', line 174

def heisei?
  created_date.heisei?
end

#humanize!Object

Rollback to human

Examples:

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

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


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

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

#nameString Also known as: to_s

Returns name of current form.

Returns:

  • (String)

    name of current form



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

def name
  state_names[current_state]
end

#reiwa?Boolean

Whether Reiwa precure

Returns:

  • (Boolean)


179
180
181
# File 'lib/rubicure/girl.rb', line 179

def reiwa?
  created_date.reiwa?
end

#state_namesArray<String>

Returns:

  • (Array<String>)


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

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:



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

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