Sha256: 0ed975d875923483b06a781bb78cce9896379abe49e3f92810dc76693d20a8bd
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module CodebrekerManfly class Difficulty < ValidatableEntity attr_reader :name, :attempts, :hints EASY = :easy MEDIUM = :medium HELL = :hell def initialize(name:, attempts:, hints:) super() @name = name @attempts = attempts @hints = hints end def <=>(other) [attempts, hints] <=> [other.attempts, other.hints] end def self.difficulties(keyword) case keyword when EASY then CodebrekerManfly::Difficulty.new(name: 'Easy', attempts: 15, hints: 2) when MEDIUM then CodebrekerManfly::Difficulty.new(name: 'Medium', attempts: 10, hints: 1) when HELL then CodebrekerManfly::Difficulty.new(name: 'Hell', attempts: 5, hints: 1) end end private def validate validate_name validate_attempts validate_hints end def validate_name return add_error(:name, I18n.t(:unexpected_class_error)) unless valid_class?(String, name) add_error(:name, I18n.t(:empty_string_error)) unless valid_non_empty_string?(name) end def validate_attempts return add_error(:attempts, I18n.t(:unexpected_class_error)) unless valid_class?(Integer, attempts) add_error(:attempts, I18n.t(:non_positive_integer_error)) unless valid_positive_integer?(attempts) end def validate_hints return add_error(:hints, I18n.t(:unexpected_class_error)) unless valid_class?(Integer, hints) add_error(:hints, I18n.t(:negative_integer_error)) unless valid_non_negative_integer?(hints) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
codebreker_manfly-0.1.2 | lib/codebreker_manfly/entities/difficulty.rb |
codebreker_manfly-0.1.1 | lib/codebreker_manfly/entities/difficulty.rb |