class Rubicure::Girl

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

this is record of “config/girls/*.yml”

Constants

ATTRIBUTES

Attributes

sleep_sec[W]
io[RW]

Public Class Methods

colors() click to toggle source

return defined colors @return [Array<Symbol>]

# 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
config() click to toggle source

@return [Hash] content of config/girls/*.yml

# 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) click to toggle source

@param girl_name [Symbol] @return [Rubicure::Girl]

# 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
names() click to toggle source

@return [Array<Symbol>]

# File lib/rubicure/girl.rb, line 204
def names
  config.keys
end
reload_config!() click to toggle source

@return [Hash] content of config/precure.yml

# File lib/rubicure/girl.rb, line 224
def reload_config!
  @cache = {}
  @config = nil
  @colors = nil
  config
end
sleep_sec() click to toggle source
# File lib/rubicure/girl.rb, line 236
def sleep_sec
  @sleep_sec ||= 1
end
uniq_names() click to toggle source

@return [Array<Symbol>]

# 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) click to toggle source

@param [Symbol] girl_name

# File lib/rubicure/girl.rb, line 232
def valid?(girl_name)
  names.include?(girl_name)
end

Public Instance Methods

==(other) click to toggle source

@return [Boolean]

# File lib/rubicure/girl.rb, line 42
def ==(other)
  other.is_a?(self.class) && self.human_name == other.human_name
end
attack!() click to toggle source

Attack to enemy

@raise [RequireTransformError] current form is human

@example

yayoi = Cure.peace
yayoi.transform!

yayoi.attack!

# プリキュア!ピースサンダー!!
# File lib/rubicure/girl.rb, line 116
def attack!
  raise RequireTransformError, "require transform" if current_attack_message.blank?

  print_by_line current_attack_message

  current_attack_message
end
birthday?(date = Date.today) click to toggle source

Whether `date` is her birthday

@param date [Date]

@return [Boolean]

@example

Cure.twinkle.birthday?(Date.parse("2015-9-12"))
#=> true
# 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_state() click to toggle source

@return [Integer]

# File lib/rubicure/girl.rb, line 30
def current_state
  @current_state ||= 0
end
full_name() click to toggle source

returns `human_full_name` or `human_name`

@return [String]

# File lib/rubicure/girl.rb, line 162
def full_name
  human_full_name.presence || human_name
end
has_birthday?()
Alias for: have_birthday?
have_birthday?() click to toggle source

Whether she has birthday

@return [Boolean]

@example

Cure.peace.have_birthday?
#=> false

Cure.twinkle.has_birthday?
#=> true
# File lib/rubicure/girl.rb, line 154
def have_birthday? # rubocop:disable Naming/PredicateName
  has_key?(:birthday)
end
Also aliased as: has_birthday?
heisei?() click to toggle source

Whether Heisei precure

# File lib/rubicure/girl.rb, line 167
def heisei?
  created_date.heisei?
end
humanize!() click to toggle source

Rollback to human

@example

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

yayoi.humanize!
yayoi.name
#=> "黄瀬やよい"
# File lib/rubicure/girl.rb, line 99
def humanize!
  @current_state = 0
  @current_transform_style = nil
  self
end
name() click to toggle source

@return [String] name of current form

# File lib/rubicure/girl.rb, line 47
def name
  state_names[current_state]
end
Also aliased as: to_s
reiwa?() click to toggle source

Whether Reiwa precure

# File lib/rubicure/girl.rb, line 172
def reiwa?
  created_date.reiwa?
end
state_names() click to toggle source

@return [Array<String>]

# 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
to_s()
Alias for: name
transform!(style = nil) click to toggle source

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

@param style [Symbol]

@return [Rubicure::Girl] self

@example

yayoi = Cure.peace

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

yayoi.transform!

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

yayoi.name
#=> "キュアピース"
# 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
  print_by_line transform_message if state == 1

  self
end

Private Instance Methods

current_attack_message() click to toggle source
# File lib/rubicure/girl.rb, line 270
def current_attack_message
  attack_messages[current_state - 1] if current_state > 0
end
has_transform_style?(style) click to toggle source
# File lib/rubicure/girl.rb, line 258
def has_transform_style?(style)
  return false unless has_key?(:transform_styles)

  transform_styles.keys.map(&:to_sym).include?(style.to_sym)
end
inc_current_state() click to toggle source
# File lib/rubicure/girl.rb, line 264
def inc_current_state
  @current_state = current_state + 1
  @current_state = 0 unless @current_state < state_names.length
  @current_state
end
method_missing(method_name, *args) click to toggle source
Calls superclass method
# 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
print_by_line(message) click to toggle source
respond_to_missing?(method_name, _include_private) click to toggle source
# File lib/rubicure/girl.rb, line 289
def respond_to_missing?(method_name, _include_private)
  # call Hashie::Extensions::MethodAccess#method_missing
  return false if has_key?(method_name)

  return false unless has_key?(:transform_calls)

  shortened_name = method_name.to_s.
                     sub(/\Aprecure_|_precure\z/, "").
                     sub(/!\z/, "")

  transform_calls.include?(shortened_name)
end