Class: Mooncats::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/mooncats/structs.rb

Defined Under Namespace

Classes: Design

Class Method Summary collapse

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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

#bObject



85
# File 'lib/mooncats/structs.rb', line 85

def b() @bytes[4]; end

#designObject



93
94
95
# File 'lib/mooncats/structs.rb', line 93

def design
  @design ||= Design.new( k % 128 )
end

#faceObject



98
# File 'lib/mooncats/structs.rb', line 98

def face()    design.face; end

#facingObject



97
# File 'lib/mooncats/structs.rb', line 97

def facing()  design.facing; end

#furObject



99
# File 'lib/mooncats/structs.rb', line 99

def fur()     design.fur; end

#gObject



84
# File 'lib/mooncats/structs.rb', line 84

def g() @bytes[3]; end

#genesis?Boolean

Returns:

  • (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

#idObject



75
76
77
# File 'lib/mooncats/structs.rb', line 75

def id
  @id ||= @bytes.map { |byte| '%02x' % byte }.join
end

#invert?Boolean

Returns:

  • (Boolean)


89
# File 'lib/mooncats/structs.rb', line 89

def invert?() k >= 128; end

#kObject



82
# File 'lib/mooncats/structs.rb', line 82

def k() @bytes[1]; end

#mintObject

more “external” attributes



105
# File 'lib/mooncats/structs.rb', line 105

def mint()   @more[:mint]; end

#patternObject

treat facing left|right as the same



90
# File 'lib/mooncats/structs.rb', line 90

def pattern() k % 64; end

#poseObject



100
# File 'lib/mooncats/structs.rb', line 100

def pose()    design.pose; end

#rObject



83
# File 'lib/mooncats/structs.rb', line 83

def r() @bytes[2]; end

#rgbObject

add rgb shortcut helper - why? why not?



87
# File 'lib/mooncats/structs.rb', line 87

def rgb() [r,g,b]; end