Class: TwistyPuzzles::MoveableCenter

Inherits:
Part
  • Object
show all
Defined in:
lib/twisty_puzzles/cube.rb

Overview

Base class of moveable centers. Represents one moveable center or the position of one moveable center on the cube.

Direct Known Subclasses

TCenter, XCenter

Constant Summary collapse

FACES =
1

Constants included from CubeConstants

CubeConstants::ALPHABET_SIZE, CubeConstants::CHIRALITY_FACE_SYMBOLS, CubeConstants::FACE_NAMES, CubeConstants::FACE_SYMBOLS, CubeConstants::OPPOSITE_FACE_SYMBOLS, CubeConstants::SKEWB_STICKERS

Instance Attribute Summary collapse

Attributes inherited from Part

#face_symbols, #piece_index

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Part

#<=>, #base_index_on_face, #base_index_on_other_face, exists_on_cube_size?, exists_on_even_cube_sizes?, exists_on_odd_cube_sizes?, #faces, for_face_symbols_internal, for_index, #hash, max_cube_size, #mirror, #num_incarnations, parse, #rotate_by_rotation, #rotate_face_symbol_up, #rotate_face_up, #rotations, #solved_coordinate, #solved_face, #to_s, #turned_equals?

Methods included from Utils::ArrayHelper

#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?

Methods included from CubeConstants

#chirality_canonical_face_symbol, #opposite_face_symbol, #valid_chirality?

Constructor Details

#initialize(corresponding_part, piece_index) ⇒ MoveableCenter

Returns a new instance of MoveableCenter.



405
406
407
408
409
410
411
412
# File 'lib/twisty_puzzles/cube.rb', line 405

def initialize(corresponding_part, piece_index)
  unless corresponding_part.is_a?(Part)
    raise "Invalid corresponding part #{corresponding_part}."
  end

  super([corresponding_part.face_symbols[0]], piece_index)
  @corresponding_part = corresponding_part
end

Instance Attribute Details

#corresponding_partObject (readonly)

Returns the value of attribute corresponding_part.



416
417
418
# File 'lib/twisty_puzzles/cube.rb', line 416

def corresponding_part
  @corresponding_part
end

Class Method Details

.for_face_symbols(face_symbols) ⇒ Object



385
386
387
388
389
390
391
392
393
394
# File 'lib/twisty_puzzles/cube.rb', line 385

def self.for_face_symbols(face_symbols)
  unless face_symbols.length == self::CORRESPONDING_PART_CLASS::FACES
    raise ArgumentError, "Need #{self::CORRESPONDING_PART_CLASS::FACES} face_symbols for a " \
                         "#{name}, have #{face_symbols.inspect}."
  end

  corresponding_part = self::CORRESPONDING_PART_CLASS.for_face_symbols(face_symbols)
  nil unless corresponding_part
  find_only(self::ELEMENTS) { |e| e.corresponding_part == corresponding_part }
end

.generate_partsObject



435
436
437
# File 'lib/twisty_puzzles/cube.rb', line 435

def self.generate_parts
  self::CORRESPONDING_PART_CLASS::ELEMENTS.map { |p| new(p, p.piece_index) }
end

.max_parseable_face_symbolsObject



373
374
375
# File 'lib/twisty_puzzles/cube.rb', line 373

def self.max_parseable_face_symbols
  self::CORRESPONDING_PART_CLASS::FACES
end

.min_cube_sizeObject



377
378
379
# File 'lib/twisty_puzzles/cube.rb', line 377

def self.min_cube_size
  4
end

.min_parseable_face_symbolsObject



369
370
371
# File 'lib/twisty_puzzles/cube.rb', line 369

def self.min_parseable_face_symbols
  self::CORRESPONDING_PART_CLASS::FACES
end

.valid?(face_symbols) ⇒ Boolean

Returns:

  • (Boolean)


381
382
383
# File 'lib/twisty_puzzles/cube.rb', line 381

def self.valid?(face_symbols)
  self::CORRESPONDING_PART_CLASS.valid?(face_symbols)
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


400
401
402
403
# File 'lib/twisty_puzzles/cube.rb', line 400

def eql?(other)
  self.class.equal?(other.class) && face_symbol == other.face_symbol &&
    @corresponding_part == other.corresponding_part
end

#face_symbolObject



396
397
398
# File 'lib/twisty_puzzles/cube.rb', line 396

def face_symbol
  @face_symbols[0]
end

#inspectObject



418
419
420
421
# File 'lib/twisty_puzzles/cube.rb', line 418

def inspect
  @inspect ||=
    "#{self.class.name.split('::').last}(#{face_symbol}, #{@corresponding_part.inspect})"
end

#neighbor?(other) ⇒ Boolean

Returns:

  • (Boolean)


427
428
429
# File 'lib/twisty_puzzles/cube.rb', line 427

def neighbor?(other)
  face_symbol == other.face_symbol
end

#neighborsObject



431
432
433
# File 'lib/twisty_puzzles/cube.rb', line 431

def neighbors
  self.class::ELEMENTS.select { |p| neighbor?(p) }
end

#rotate_by(_number) ⇒ Object



423
424
425
# File 'lib/twisty_puzzles/cube.rb', line 423

def rotate_by(_number)
  self
end