elite_universe 0.0.5 → 0.1.0
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 +5 -5
- data/README.md +7 -2
- data/lib/elite_universe/galaxy.rb +13 -8
- data/lib/elite_universe/planet.rb +25 -21
- data/lib/elite_universe/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad122bcb1e33808aab6afd7f2838dfcbd1b00cf55a167b90b873f38dc0862a37
|
4
|
+
data.tar.gz: f2cf4dff439959ea227090530f34a86519e68a72fa80af1d7209a341f318e1ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0db1cb366a2c1cdf8649bef96ebcf597cc108704253c0e57eb50ecc5f4b25df3c91047f58ea8cbf45203713f99cac280291100a7b8d22c1f33222ba4d7b7ea8
|
7
|
+
data.tar.gz: 5cf23fb0fe096b129bd1022cef43d8662a74a42a0940aaac692ee4f02bff2df116c9701b27f3b7cae17b91eb9cd2512921d27835875a38d7e7270d00f9992b04
|
data/README.md
CHANGED
@@ -18,8 +18,7 @@ planet.name # = Lave
|
|
18
18
|
require 'elite_universe/galaxy'
|
19
19
|
|
20
20
|
galaxy = EliteUniverse::Galaxy.new(23114, 584, 46931)
|
21
|
-
galaxy.
|
22
|
-
galaxy.planets[129].name # = Zaonce
|
21
|
+
galaxy[129].name # = Zaonce
|
23
22
|
```
|
24
23
|
|
25
24
|
`EliteUniverse::Galaxy` is an Enumerable class and so, for example, a full list
|
@@ -29,6 +28,12 @@ of planet names in the galaxy can be generated with:
|
|
29
28
|
galaxy.map(&:name)
|
30
29
|
```
|
31
30
|
|
31
|
+
## Deprecated methods
|
32
|
+
|
33
|
+
`galaxy.planets` will return an array of all instances of
|
34
|
+
`EliteUniverse::Planet` in an `EliteUniverse::Galaxy`. This is deprecated.
|
35
|
+
Instead of `galaxy.planets[i]` use `galaxy[i]`.
|
36
|
+
|
32
37
|
## License
|
33
38
|
|
34
39
|
The Elite Universe gem is available to everyone under the terms of the MIT
|
@@ -5,19 +5,24 @@ module EliteUniverse
|
|
5
5
|
include Enumerable
|
6
6
|
|
7
7
|
def initialize a, b, c
|
8
|
-
@
|
8
|
+
@initial_planet = Planet.new(a, b, c)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
p
|
11
|
+
def each &block
|
12
|
+
256.times.inject(@initial_planet) do |p|
|
13
|
+
block.call(p)
|
14
|
+
p.next
|
15
15
|
end
|
16
|
-
p
|
17
16
|
end
|
18
17
|
|
19
|
-
def
|
20
|
-
|
18
|
+
def planets
|
19
|
+
puts "DEPRECATED"
|
20
|
+
puts "In place of `galaxy.planets[n]` use `galaxy[n]`"
|
21
|
+
self.map { |p| p }
|
22
|
+
end
|
23
|
+
|
24
|
+
def [] n
|
25
|
+
n.times.inject(@initial_planet) { |p| p.next }
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
@@ -28,35 +28,30 @@ module EliteUniverse
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def name
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
n = ( v[2] >> 8 ) & 31
|
37
|
-
name += CHARS[n]
|
38
|
-
end
|
39
|
-
v = twist v
|
40
|
-
end
|
41
|
-
name.gsub('.', '').capitalize
|
31
|
+
(@w[0] & 64 == 0 ? 2 : 3).times.inject([@w]) do |vs|
|
32
|
+
vs << twist(vs[-1])
|
33
|
+
end.inject('') do |name, v|
|
34
|
+
name += CHARS[(v[2] >> 8) & 31]
|
35
|
+
end.tr('.', '').capitalize
|
42
36
|
end
|
43
37
|
|
44
38
|
def government
|
45
|
-
GOVS[
|
39
|
+
GOVS[gov_n]
|
46
40
|
end
|
47
41
|
|
48
42
|
def economy
|
49
|
-
ECONS[
|
43
|
+
ECONS[econ_n]
|
50
44
|
end
|
51
45
|
|
52
46
|
def location
|
53
|
-
[
|
47
|
+
[@w[1] >> 8, @w[0] >> 8]
|
54
48
|
end
|
55
49
|
|
56
50
|
def technology
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
((@w[1] >> 8 ) & 3) +
|
52
|
+
(econ_n ^ 7) +
|
53
|
+
(gov_n >> 1) +
|
54
|
+
((gov_n & 1) == 1 ? 2 : 1)
|
60
55
|
end
|
61
56
|
|
62
57
|
def next
|
@@ -64,17 +59,26 @@ module EliteUniverse
|
|
64
59
|
end
|
65
60
|
|
66
61
|
private
|
62
|
+
|
63
|
+
def version_at_least version
|
64
|
+
# ... because I want to use new features if possible
|
65
|
+
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version)
|
66
|
+
end
|
67
|
+
|
67
68
|
def twist arr
|
68
|
-
[
|
69
|
+
[
|
70
|
+
arr[1],
|
71
|
+
arr[2],
|
72
|
+
(version_at_least('2.4.0') ? arr.sum : arr.inject(:+)) % 65536
|
73
|
+
]
|
69
74
|
end
|
70
75
|
|
71
76
|
def gov_n
|
72
|
-
(
|
77
|
+
(@w[1] >> 3) & 7
|
73
78
|
end
|
74
79
|
|
75
80
|
def econ_n
|
76
|
-
|
77
|
-
gov_n <= 1 ? e | 2 : e
|
81
|
+
((@w[0] >> 8) & 7) | (gov_n <= 1 ? 2 : 0)
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elite_universe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Haig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.6
|
59
|
+
rubygems_version: 2.7.6
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Elite Universe
|