twisty_puzzles 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twisty_puzzles/cube.rb +4 -0
- data/lib/twisty_puzzles/part_cycle.rb +25 -0
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be82a2641267d469bc68c47799c03783467777a5b8279e5d9dcf7341de653ed6
|
4
|
+
data.tar.gz: '048163ad5b5711cbfa50e6a5a63157938f5fe77cf4185e069d0093d29faf2159'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fb21ebf301992496ae43c9c7139bd518db0d7973020b78a8151fce1799e406eae182e0585d862493a22c6ae6d6168d17e9be81cda858fbca261f50651a803ea
|
7
|
+
data.tar.gz: 526eba7127c4c83a9f3c1b1a8c6addb270a678e37311bada9418cfd74455590753f2ae756a9b0454008d9965cac563dd30fd6d1929e1935969fd0c3e643a5ec4
|
data/lib/twisty_puzzles/cube.rb
CHANGED
@@ -13,6 +13,8 @@ module TwistyPuzzles
|
|
13
13
|
include Utils::ArrayHelper
|
14
14
|
|
15
15
|
def initialize(parts)
|
16
|
+
raise ArgumentError if parts.empty?
|
17
|
+
|
16
18
|
check_types(parts, Part)
|
17
19
|
check_type_consistency(parts)
|
18
20
|
|
@@ -31,6 +33,29 @@ module TwistyPuzzles
|
|
31
33
|
@hash ||= ([self.class] + @parts).hash
|
32
34
|
end
|
33
35
|
|
36
|
+
def part_type
|
37
|
+
@parts.first.class
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
@parts.join(' ')
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_raw_data
|
45
|
+
"#{part_type}(#{self})"
|
46
|
+
end
|
47
|
+
|
48
|
+
def length
|
49
|
+
@parts.length
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.from_raw_data(data)
|
53
|
+
raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
|
54
|
+
part_type = PART_TYPES.find { |p| p.name == raw_part_type }
|
55
|
+
parts = raw_parts.split.map { |r| part_type.parse(r) }
|
56
|
+
new(parts)
|
57
|
+
end
|
58
|
+
|
34
59
|
def check_type_consistency(parts)
|
35
60
|
return unless parts.any? { |p| p.class != parts.first.class }
|
36
61
|
|