class Mooncats::Metadata
Public Class Methods
hex_to_bytes( str_or_num )
click to toggle source
(static) helpers
# File lib/mooncats/structs.rb, line 224 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
new( id, **more )
click to toggle source
# File lib/mooncats/structs.rb, line 87 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
Public Instance Methods
[]( key )
click to toggle source
enable array-like access to - why? why not?
# File lib/mooncats/structs.rb, line 195 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, :pale then invert? when :hue then hue when :color then color when :design then design.to_i when :pattern then pattern when :facing then facing when :face, :expression then face when :fur then fur when :pose then pose when :year then year # note: from more via timestamp else @more[ key ] end end
b()
click to toggle source
# File lib/mooncats/structs.rb, line 105 def b() @bytes[4]; end
block()
click to toggle source
# File lib/mooncats/structs.rb, line 189 def block() @more[:block]; end
color()
click to toggle source
# File lib/mooncats/structs.rb, line 132 def color case hue when 345..359, 0..14 then 'Red' when 15..44 then 'Orange' when 45..74 then 'Yellow' when 75..104 then 'Chartreuse' when 105..134 then 'Green' when 135..164 then 'Teal' when 165..194 then 'Cyan' when 195..224 then 'Sky Blue' when 225..254 then 'Blue' when 255..284 then 'Purple' when 285..314 then 'Magenta' when 315..344 then 'Fuchsia' else puts "!! ERROR - unexpected hue (in degress); got #{hue} - expected 0 to 359" exit 1 end end
design()
click to toggle source
# File lib/mooncats/structs.rb, line 175 def design @design ||= Design.new( k % 128 ) end
face()
click to toggle source
# File lib/mooncats/structs.rb, line 180 def face() design.face; end
Also aliased as: expression
facing()
click to toggle source
# File lib/mooncats/structs.rb, line 179 def facing() design.facing; end
fur()
click to toggle source
# File lib/mooncats/structs.rb, line 182 def fur() design.fur; end
g()
click to toggle source
# File lib/mooncats/structs.rb, line 104 def g() @bytes[3]; end
genesis?()
click to toggle source
# File lib/mooncats/structs.rb, line 99 def genesis? @bytes[0] != 0 ## note: convert to bool (if zero assume NOT genesis) end
hue()
click to toggle source
# File lib/mooncats/structs.rb, line 116 def hue @hue ||= begin ## note: hsl[0], that is, hue MIGHT BE NEGATIVE! ## e.g. try rbg( 91, 27, 41 ) ## resulting in ## hsl( -13, 0.5423728813559322, 0.23137254901960785 ) ## remember: always use % 360 to make positive!!! ## e.g. -13 % 360 => 347 ## -25 % 360 => 335 rgb = ChunkyPNG::Color.rgb( r, g, b ) hsl = ChunkyPNG::Color.to_hsl( rgb ) hsl[0] % 360 ## make sure number is always POSITIVE!!! end end
id()
click to toggle source
# File lib/mooncats/structs.rb, line 95 def id @id ||= @bytes.map { |byte| '%02x' % byte }.join end
invert?()
click to toggle source
# File lib/mooncats/structs.rb, line 109 def invert?() k >= 128; end
Also aliased as: pale?
k()
click to toggle source
# File lib/mooncats/structs.rb, line 102 def k() @bytes[1]; end
mint()
click to toggle source
more “external” attributes
# File lib/mooncats/structs.rb, line 188 def mint() @more[:mint]; end
pattern()
click to toggle source
# File lib/mooncats/structs.rb, line 113 def pattern() k % 64; end
pose()
click to toggle source
# File lib/mooncats/structs.rb, line 183 def pose() design.pose; end
r()
click to toggle source
# File lib/mooncats/structs.rb, line 103 def r() @bytes[2]; end
rgb()
click to toggle source
# File lib/mooncats/structs.rb, line 107 def rgb() [r,g,b]; end
timestamp()
click to toggle source
# File lib/mooncats/structs.rb, line 190 def timestamp() @more[:timestamp]; end
xxx_color_old_formula()
click to toggle source
# File lib/mooncats/structs.rb, line 154 def xxx_color_old_formula ## remove - move to attic?? case hue when 0..29 then 'Red' when 30..59 then 'Orange' when 60..89 then 'Yellow' when 90..119 then 'Chartreuse' when 120..149 then 'Green' when 150..179 then 'Lime Green' ## now renamed to Teal when 180..209 then 'Cyan' when 210..239 then 'Sky Blue' when 240..269 then 'Blue' when 270..299 then 'Purple' when 300..329 then 'Magenta' when 330..359 then 'Fuchsia' else puts "!! ERROR - unexpected hue (in degress); got #{hue} - expected 0 to 359" exit 1 end end
year()
click to toggle source
# File lib/mooncats/structs.rb, line 191 def year() timestamp ? timestamp.year : nil; end