cryptopunks 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +1,55 @@
1
-
2
-
3
- class CryptopunksData ## check - change class to a module - why? why not?
4
-
5
-
6
- def self.meta
7
- ## get all meta data records for all 10 000 punks
8
- @meta ||= decode_meta( META_ENCODED )
9
- end
10
-
11
- def self.assets
12
- @assets ||= ASSETS_ENCODED.sort { |l,r| l[:id] <=> r[:id] }
13
- end
14
-
15
-
16
-
17
- def self.punk_attributes( id )
18
- ## comma-separated values / attribute list in a string
19
- asset_nums = meta[ id ] ## id - integer number e.g. 0,1,2,
20
-
21
- asset_nums.map do |num|
22
- ## note: ASSETS_ENCODED array is zero-based; subtract -1 to start with zero (not one)
23
- assets[ num-1 ][:name]
24
- end
25
- end
26
-
27
- class << self
28
- alias_method :attributes, :punk_attributes
29
- end
30
-
31
-
32
- ###
33
- # more helpers
34
- def self.decode_meta( hex )
35
- recs = []
36
-
37
- ## note: allow spaces and newlines in hexstring for formatting
38
- hex = hex.gsub( /[ \n]/, '' )
39
-
40
- ## convert hex string to byte array, that is, array of integer numbers
41
- ## e.g. 067d7a7e00000000 (0x06 / 0x7d / 0x7a / 0x7e / 0x00 / 0x00 ..)
42
- ## => [6, 125, 122, 126, 0, 0, 0, 0]
43
- a = [hex].pack("H*").unpack('C*')
44
-
45
- a.each_slice( 8 ).with_index do |attributes,i|
46
- ## filter out (trailing) zeros (0)
47
- attributes = attributes.filter { |num| num != 0 }
48
- ## puts "#{i} => #{attributes.inspect}"
49
-
50
- recs << attributes
51
- end
52
- recs
53
- end
54
- end # class CryptopunksData
55
-
1
+
2
+
3
+ class CryptopunksData ## check - change class to a module - why? why not?
4
+
5
+
6
+ def self.meta
7
+ ## get all meta data records for all 10 000 punks
8
+ @meta ||= decode_meta( META_ENCODED )
9
+ end
10
+
11
+ def self.assets
12
+ @assets ||= ASSETS_ENCODED.sort { |l,r| l[:id] <=> r[:id] }
13
+ end
14
+
15
+
16
+
17
+ def self.punk_attributes( id )
18
+ ## comma-separated values / attribute list in a string
19
+ asset_nums = meta[ id ] ## id - integer number e.g. 0,1,2,
20
+
21
+ asset_nums.map do |num|
22
+ ## note: ASSETS_ENCODED array is zero-based; subtract -1 to start with zero (not one)
23
+ assets[ num-1 ][:name]
24
+ end
25
+ end
26
+
27
+ class << self
28
+ alias_method :attributes, :punk_attributes
29
+ end
30
+
31
+
32
+ ###
33
+ # more helpers
34
+ def self.decode_meta( hex )
35
+ recs = []
36
+
37
+ ## note: allow spaces and newlines in hexstring for formatting
38
+ hex = hex.gsub( /[ \n]/, '' )
39
+
40
+ ## convert hex string to byte array, that is, array of integer numbers
41
+ ## e.g. 067d7a7e00000000 (0x06 / 0x7d / 0x7a / 0x7e / 0x00 / 0x00 ..)
42
+ ## => [6, 125, 122, 126, 0, 0, 0, 0]
43
+ a = [hex].pack("H*").unpack('C*')
44
+
45
+ a.each_slice( 8 ).with_index do |attributes,i|
46
+ ## filter out (trailing) zeros (0)
47
+ attributes = attributes.filter { |num| num != 0 }
48
+ ## puts "#{i} => #{attributes.inspect}"
49
+
50
+ recs << attributes
51
+ end
52
+ recs
53
+ end
54
+ end # class CryptopunksData
55
+