Class: Rubicure::Girl
- Inherits:
-
Hash
- Object
- Hash
- Rubicure::Girl
- 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
-
.colors ⇒ Array<Symbol>
return defined colors.
-
.config ⇒ Hash
Content of config/girls/*.yml.
- .find(girl_name) ⇒ Rubicure::Girl
- .names ⇒ Array<Symbol>
-
.reload_config! ⇒ Hash
Content of config/precure.yml.
- .uniq_names ⇒ Array<Symbol>
- .valid?(girl_name) ⇒ Boolean
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#attack! ⇒ Object
Attack to enemy.
-
#birthday?(date = Date.today) ⇒ Boolean
Whether
date
is her birthday. - #current_state ⇒ Integer
-
#full_name ⇒ String
returns
human_full_name
orhuman_name
. -
#have_birthday? ⇒ Boolean
(also: #has_birthday?)
Whether she has birthday.
-
#heisei? ⇒ Boolean
Whether Heisei precure.
-
#humanize! ⇒ Object
Rollback to human.
-
#name ⇒ String
(also: #to_s)
Name of current form.
-
#reiwa? ⇒ Boolean
Whether Reiwa precure.
- #state_names ⇒ Array<String>
-
#transform!(style = nil) ⇒ Rubicure::Girl
human -> precure ( -> extra forms ) -> human …
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_sec ⇒ Object
243 244 245 |
# File 'lib/rubicure/girl.rb', line 243 def sleep_sec @sleep_sec ||= 1 end |
Class Method Details
.colors ⇒ Array<Symbol>
return defined colors
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 |
.config ⇒ Hash
Returns 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
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 |
.names ⇒ 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.
231 232 233 234 235 236 |
# File 'lib/rubicure/girl.rb', line 231 def reload_config! @cache = {} @config = nil @colors = nil config end |
.uniq_names ⇒ 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
239 240 241 |
# File 'lib/rubicure/girl.rb', line 239 def valid?(girl_name) names.include?(girl_name) end |
Instance Method Details
#==(other) ⇒ 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
123 124 125 126 127 128 129 |
# File 'lib/rubicure/girl.rb', line 123 def attack! raise RequireTransformError, "require transform" if .blank? print_by_line end |
#birthday?(date = Date.today) ⇒ Boolean
Whether date
is her birthday
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_state ⇒ Integer
29 30 31 |
# File 'lib/rubicure/girl.rb', line 29 def current_state @current_state ||= 0 end |
#full_name ⇒ String
returns human_full_name
or human_name
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
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
174 175 176 |
# File 'lib/rubicure/girl.rb', line 174 def heisei? created_date.heisei? end |
#humanize! ⇒ Object
Rollback to human
106 107 108 109 110 |
# File 'lib/rubicure/girl.rb', line 106 def humanize! @current_state = 0 @current_transform_style = nil self end |
#name ⇒ String Also known as: to_s
Returns 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
179 180 181 |
# File 'lib/rubicure/girl.rb', line 179 def reiwa? created_date.reiwa? end |
#state_names ⇒ 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 …
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 = if random_transform_words && !random_transform_words.empty? random_transform_word = random_transform_words.sample .gsub("${random_transform_word}", random_transform_word) else end print_by_line if state == 1 self end |