Class: Stroop::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/stroop/set.rb

Constant Summary collapse

NEUTRAL =
:neutral
CONGRUENT =
:congruent
INCONGRUENT =
:incongruent
MODES =
[NEUTRAL, CONGRUENT, INCONGRUENT].freeze
BOX =
{
  vertical: "┊",
  horizontal: "┄",
  top_left: "┌",
  top_right: "┐",
  bottom_left: "└",
  bottom_right: "┘"
}.transform_values(&:light_black).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows:, columns:, mode:, seed: nil) ⇒ Set

Returns a new instance of Set.



24
25
26
27
28
29
30
31
32
# File 'lib/stroop/set.rb', line 24

def initialize(rows:, columns:, mode:, seed: nil)
  raise SetModeNotAvailable.new unless MODES.include?(mode)

  @rows = rows.to_i.abs
  @columns = columns.to_i.abs
  @mode = mode.to_sym
  @generator = ColorGenerator.new(seed: seed)
  @seed = @generator.seed
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



22
23
24
# File 'lib/stroop/set.rb', line 22

def columns
  @columns
end

#modeObject (readonly)

Returns the value of attribute mode.



22
23
24
# File 'lib/stroop/set.rb', line 22

def mode
  @mode
end

#rowsObject (readonly)

Returns the value of attribute rows.



22
23
24
# File 'lib/stroop/set.rb', line 22

def rows
  @rows
end

#seedObject (readonly)

Returns the value of attribute seed.



22
23
24
# File 'lib/stroop/set.rb', line 22

def seed
  @seed
end

Instance Method Details

#to_sObject



34
35
36
# File 'lib/stroop/set.rb', line 34

def to_s
  [empty_line(:top), *lines, empty_line(:bottom)].join("\n")
end