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, :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
-
.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
dateis her birthday. - #current_state ⇒ Integer
-
#full_name ⇒ String
returns
human_full_nameorhuman_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.
-
#real_name ⇒ String
returns
human_real_nameorhuman_name. -
#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)
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
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.
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
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>
219 220 221 |
# File 'lib/rubicure/girl.rb', line 219 def names config.keys end |
.reload_config! ⇒ Hash
Returns 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>
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
247 248 249 |
# File 'lib/rubicure/girl.rb', line 247 def valid?(girl_name) names.include?(girl_name) end |
Instance Method Details
#==(other) ⇒ 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
124 125 126 127 128 129 130 |
# File 'lib/rubicure/girl.rb', line 124 def attack! raise RequireTransformError, "require transform" if .blank? print_by_line end |
#birthday?(date = Date.today) ⇒ Boolean
Whether date is her birthday
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
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
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
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
182 183 184 |
# File 'lib/rubicure/girl.rb', line 182 def heisei? created_date.heisei? end |
#humanize! ⇒ Object
Rollback to human
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.
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
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
187 188 189 |
# File 'lib/rubicure/girl.rb', line 187 def reiwa? created_date.reiwa? end |
#state_names ⇒ 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 ...
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 = 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 |