class RubiksCube::StickerStateTransform
Transform manual sticker state entry to cube state
Constants
- CENTER_LOCATIONS
- CORNER_LOCATIONS
- EDGE_LOCATIONS
Attributes
state[R]
Public Class Methods
new(state)
click to toggle source
# File lib/rubiks_cube/sticker_state_transform.rb, line 19 def initialize(state) @state = state.gsub(/\s/, '').split('') end
Public Instance Methods
to_cube()
click to toggle source
# File lib/rubiks_cube/sticker_state_transform.rb, line 23 def to_cube (edges + corners).join(' ').gsub(/./) { |c| color_mapping.fetch(c, c) } end
Private Instance Methods
color_mapping()
click to toggle source
# File lib/rubiks_cube/sticker_state_transform.rb, line 29 def color_mapping Hash[state.values_at(*CENTER_LOCATIONS).zip %w(F R B L U D)] end
corners()
click to toggle source
# File lib/rubiks_cube/sticker_state_transform.rb, line 37 def corners state.values_at(*CORNER_LOCATIONS).each_slice(3).map(&:join) end
edges()
click to toggle source
# File lib/rubiks_cube/sticker_state_transform.rb, line 33 def edges state.values_at(*EDGE_LOCATIONS).each_slice(2).map(&:join) end