Class: Mooncats::Metadata
- Inherits:
-
Object
- Object
- Mooncats::Metadata
- Defined in:
- lib/mooncats/structs.rb
Defined Under Namespace
Classes: Design
Class Method Summary collapse
-
.hex_to_bytes(str_or_num) ⇒ Object
(static) helpers.
Instance Method Summary collapse
-
#[](key) ⇒ Object
enable array-like access to - why? why not?.
- #b ⇒ Object
- #design ⇒ Object
- #face ⇒ Object
- #facing ⇒ Object
- #fur ⇒ Object
- #g ⇒ Object
- #genesis? ⇒ Boolean
- #id ⇒ Object
-
#initialize(id, **more) ⇒ Metadata
constructor
A new instance of Metadata.
- #invert? ⇒ Boolean
- #k ⇒ Object
-
#mint ⇒ Object
more “external” attributes.
-
#pattern ⇒ Object
treat facing left|right as the same.
- #pose ⇒ Object
- #r ⇒ Object
-
#rgb ⇒ Object
add rgb shortcut helper - why? why not?.
Constructor Details
#initialize(id, **more) ⇒ Metadata
Returns a new instance of Metadata.
67 68 69 70 71 72 73 |
# File 'lib/mooncats/structs.rb', line 67 def initialize( id, **more ) @bytes = self.class.hex_to_bytes( id ) ## add support for more "external" meta data ## ## e.g. mint, mint_block, etc. @more = more end |
Class Method Details
.hex_to_bytes(str_or_num) ⇒ Object
(static) helpers
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mooncats/structs.rb', line 133 def self.hex_to_bytes( str_or_num ) if str_or_num.is_a?( Integer ) ## allow passing in of integer to e.g. 0x... etc. num = str_or_num str = '%010x' % num # 5 bytes (10 hex digits/chars) else ## assume string ## cut-off optionial 0x str = str_or_num str = str.downcase str = str[2..-1] if str.start_with?( '0x') end raise ArgumentError, "expected 5 byte hex string (10 digits/chars); got #{str_or_num}" if str.size != 10 bytes = [str].pack('H*').bytes bytes end |
Instance Method Details
#[](key) ⇒ Object
enable array-like access to - why? why not?
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/mooncats/structs.rb', line 109 def []( key ) case key.to_sym when :id then id when :genesis then genesis? when :k then k when :r then r when :g then g when :b then b when :rgb then rgb when :invert then invert? when :design then design.to_i when :pattern then pattern when :facing then facing when :face then face when :fur then fur when :pose then pose else @more[ key ] end end |
#b ⇒ Object
85 |
# File 'lib/mooncats/structs.rb', line 85 def b() @bytes[4]; end |
#design ⇒ Object
93 94 95 |
# File 'lib/mooncats/structs.rb', line 93 def design @design ||= Design.new( k % 128 ) end |
#face ⇒ Object
98 |
# File 'lib/mooncats/structs.rb', line 98 def face() design.face; end |
#facing ⇒ Object
97 |
# File 'lib/mooncats/structs.rb', line 97 def facing() design.facing; end |
#fur ⇒ Object
99 |
# File 'lib/mooncats/structs.rb', line 99 def fur() design.fur; end |
#g ⇒ Object
84 |
# File 'lib/mooncats/structs.rb', line 84 def g() @bytes[3]; end |
#genesis? ⇒ Boolean
79 80 81 |
# File 'lib/mooncats/structs.rb', line 79 def genesis? @bytes[0] != 0 ## note: convert to bool (if zero assume NOT genesis) end |
#id ⇒ Object
75 76 77 |
# File 'lib/mooncats/structs.rb', line 75 def id @id ||= @bytes.map { |byte| '%02x' % byte }.join end |
#invert? ⇒ Boolean
89 |
# File 'lib/mooncats/structs.rb', line 89 def invert?() k >= 128; end |
#k ⇒ Object
82 |
# File 'lib/mooncats/structs.rb', line 82 def k() @bytes[1]; end |
#mint ⇒ Object
more “external” attributes
105 |
# File 'lib/mooncats/structs.rb', line 105 def mint() @more[:mint]; end |
#pattern ⇒ Object
treat facing left|right as the same
90 |
# File 'lib/mooncats/structs.rb', line 90 def pattern() k % 64; end |
#pose ⇒ Object
100 |
# File 'lib/mooncats/structs.rb', line 100 def pose() design.pose; end |
#r ⇒ Object
83 |
# File 'lib/mooncats/structs.rb', line 83 def r() @bytes[2]; end |
#rgb ⇒ Object
add rgb shortcut helper - why? why not?
87 |
# File 'lib/mooncats/structs.rb', line 87 def rgb() [r,g,b]; end |