Class: MastermindGenerator::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind_generator/sequence.rb

Overview

Respresents valid sequence that created according to difficulty level

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(difficulty, value) ⇒ Sequence

Returns a new instance of Sequence.



29
30
31
32
33
34
35
36
# File 'lib/mastermind_generator/sequence.rb', line 29

def initialize(difficulty, value)
  @difficulty = difficulty
  @items = MastermindGenerator
           .configuration
           .items[..difficulty.item_count - 1]
           .map { Item.new(_1) }
  @value = validate(value)
end

Instance Attribute Details

#difficultyObject (readonly)

Returns the value of attribute difficulty.



27
28
29
# File 'lib/mastermind_generator/sequence.rb', line 27

def difficulty
  @difficulty
end

#itemsObject (readonly)

Returns the value of attribute items.



27
28
29
# File 'lib/mastermind_generator/sequence.rb', line 27

def items
  @items
end

#valueObject (readonly)

Returns the value of attribute value.



27
28
29
# File 'lib/mastermind_generator/sequence.rb', line 27

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/mastermind_generator/sequence.rb', line 42

def ==(other)
  value == other.value
end

#codesObject



38
39
40
# File 'lib/mastermind_generator/sequence.rb', line 38

def codes
  items.map(&:code)
end