Class: CodebrekerManfly::Difficulty

Inherits:
ValidatableEntity show all
Defined in:
lib/codebreker_manfly/entities/difficulty.rb

Constant Summary collapse

EASY =
:easy
MEDIUM =
:medium
HELL =
:hell

Instance Attribute Summary collapse

Attributes inherited from ValidatableEntity

#errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValidatableEntity

#valid?

Methods included from Validator

#valid_class?, #valid_non_empty_string?, #valid_non_negative_integer?, #valid_only_numeric_string?, #valid_positive_integer?, #valid_range?, #valid_string_max_length?, #valid_string_min_length?

Constructor Details

#initialize(name:, attempts:, hints:) ⇒ Difficulty

Returns a new instance of Difficulty.



11
12
13
14
15
16
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 11

def initialize(name:, attempts:, hints:)
  super()
  @name = name
  @attempts = attempts
  @hints = hints
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



5
6
7
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 5

def attempts
  @attempts
end

#hintsObject (readonly)

Returns the value of attribute hints.



5
6
7
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 5

def hints
  @hints
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 5

def name
  @name
end

Class Method Details

.difficulties(keyword) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 22

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

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
# File 'lib/codebreker_manfly/entities/difficulty.rb', line 18

def <=>(other)
  [attempts, hints] <=> [other.attempts, other.hints]
end