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
- #block ⇒ Object
- #color ⇒ Object
- #design ⇒ Object
- #face ⇒ Object (also: #expression)
- #facing ⇒ Object
- #fur ⇒ Object
- #g ⇒ Object
- #genesis? ⇒ Boolean
- #hue ⇒ Object
- #id ⇒ Object
-
#initialize(id, **more) ⇒ Metadata
constructor
A new instance of Metadata.
- #invert? ⇒ Boolean (also: #pale?)
- #k ⇒ Object
-
#mint ⇒ Object
more “external” attributes.
-
#pattern ⇒ Object
treat facing left|right as the same - note: conflicts with fur (pattern) - find a better/different name?.
- #pose ⇒ Object
- #r ⇒ Object
-
#rgb ⇒ Object
add rgb shortcut helper - why? why not?.
- #timestamp ⇒ Object
-
#xxx_color_old_formula ⇒ Object
remove - move to attic??.
- #year ⇒ Object
Constructor Details
#initialize(id, **more) ⇒ Metadata
Returns a new instance of Metadata.
87 88 89 90 91 92 93 |
# 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 |
Class Method Details
.hex_to_bytes(str_or_num) ⇒ Object
(static) helpers
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
enable array-like access to - why? why not?
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# 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 ⇒ Object
105 |
# File 'lib/mooncats/structs.rb', line 105 def b() @bytes[4]; end |
#block ⇒ Object
189 |
# File 'lib/mooncats/structs.rb', line 189 def block() @more[:block]; end |
#color ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# 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 ⇒ Object
175 176 177 |
# File 'lib/mooncats/structs.rb', line 175 def design @design ||= Design.new( k % 128 ) end |
#face ⇒ Object Also known as: expression
180 |
# File 'lib/mooncats/structs.rb', line 180 def face() design.face; end |
#facing ⇒ Object
179 |
# File 'lib/mooncats/structs.rb', line 179 def facing() design.facing; end |
#fur ⇒ Object
182 |
# File 'lib/mooncats/structs.rb', line 182 def fur() design.fur; end |
#g ⇒ Object
104 |
# File 'lib/mooncats/structs.rb', line 104 def g() @bytes[3]; end |
#genesis? ⇒ Boolean
99 100 101 |
# File 'lib/mooncats/structs.rb', line 99 def genesis? @bytes[0] != 0 ## note: convert to bool (if zero assume NOT genesis) end |
#hue ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# 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 ⇒ Object
95 96 97 |
# File 'lib/mooncats/structs.rb', line 95 def id @id ||= @bytes.map { |byte| '%02x' % byte }.join end |
#invert? ⇒ Boolean Also known as: pale?
109 |
# File 'lib/mooncats/structs.rb', line 109 def invert?() k >= 128; end |
#k ⇒ Object
102 |
# File 'lib/mooncats/structs.rb', line 102 def k() @bytes[1]; end |
#mint ⇒ Object
more “external” attributes
188 |
# File 'lib/mooncats/structs.rb', line 188 def mint() @more[:mint]; end |
#pattern ⇒ Object
treat facing left|right as the same - note: conflicts with fur (pattern) - find a better/different name?
113 |
# File 'lib/mooncats/structs.rb', line 113 def pattern() k % 64; end |
#pose ⇒ Object
183 |
# File 'lib/mooncats/structs.rb', line 183 def pose() design.pose; end |
#r ⇒ Object
103 |
# File 'lib/mooncats/structs.rb', line 103 def r() @bytes[2]; end |
#rgb ⇒ Object
add rgb shortcut helper - why? why not?
107 |
# File 'lib/mooncats/structs.rb', line 107 def rgb() [r,g,b]; end |
#timestamp ⇒ Object
190 |
# File 'lib/mooncats/structs.rb', line 190 def () @more[:timestamp]; end |
#xxx_color_old_formula ⇒ Object
remove - move to attic??
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# 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 ⇒ Object
191 |
# File 'lib/mooncats/structs.rb', line 191 def year() ? .year : nil; end |