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,
].freeze

Class Attribute Summary collapse

Instance 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)


283
284
285
286
287
# File 'lib/rubicure/girl.rb', line 283

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

  transform!(*args)
end

Class Attribute Details

.sleep_secObject


236
237
238
# File 'lib/rubicure/girl.rb', line 236

def sleep_sec
  @sleep_sec ||= 1
end

Instance Attribute Details

#ioObject

Returns the value of attribute io


27
28
29
# File 'lib/rubicure/girl.rb', line 27

def io
  @io
end

Class Method Details

.colorsArray<Symbol>

return defined colors

Returns:

  • (Array<Symbol>)

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

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


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

def config
  unless @config
    @config = SengiriYaml.load_dir("#{File.dirname(__FILE__)}/../../config/girls").deep_symbolize_keys
  end
  @config
end

.find(girl_name) ⇒ Rubicure::Girl

Parameters:

  • girl_name (Symbol)

Returns:


191
192
193
194
195
196
197
198
199
200
201
# File 'lib/rubicure/girl.rb', line 191

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].tap {|girl| girl.io = $stdout }
  end

  @cache[girl_name]
end

.namesArray<Symbol>

Returns:

  • (Array<Symbol>)

204
205
206
# File 'lib/rubicure/girl.rb', line 204

def names
  config.keys
end

.reload_config!Hash

Returns content of config/precure.yml.

Returns:

  • (Hash)

    content of config/precure.yml


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

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

.uniq_namesArray<Symbol>

Returns:

  • (Array<Symbol>)

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

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)

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

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:


116
117
118
119
120
121
122
# File 'lib/rubicure/girl.rb', line 116

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)

133
134
135
136
137
138
139
140
141
142
# File 'lib/rubicure/girl.rb', line 133

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)

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

def current_state
  @current_state ||= 0
end

#full_nameString

returns human_full_name or human_name

Returns:

  • (String)

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

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)

154
155
156
# File 'lib/rubicure/girl.rb', line 154

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

#heisei?Boolean

Whether Heisei precure

Returns:

  • (Boolean)

167
168
169
# File 'lib/rubicure/girl.rb', line 167

def heisei?
  created_date.heisei?
end

#humanize!Object

Rollback to human

Examples:

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

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

99
100
101
102
103
# File 'lib/rubicure/girl.rb', line 99

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


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

def name
  state_names[current_state]
end

#reiwa?Boolean

Whether Reiwa precure

Returns:

  • (Boolean)

172
173
174
# File 'lib/rubicure/girl.rb', line 172

def reiwa?
  created_date.reiwa?
end

#state_namesArray<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
# 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
   transform_message if state == 1

  self
end