class Genome
Attributes
genes[R]
Public Class Methods
new( arg )
click to toggle source
# File lib/copycats/genome.rb, line 7 def initialize( arg ) if arg.is_a? Hash hash = arg ## assumes (pre-built) hash with genes @genes = hash else if arg.is_a? Integer ## use Integer (Fixnum+Bignum??) - why? why not? num = arg kai = Kai.encode( num ) else # else assume string in kai/base32 format kai = arg.dup # just in case; make a clean (fresh) copy kai = kai.gsub( ' ', '' ) ## allow spaces (strip/remove) end ## puts "Genome.initialize #{kai}" build_genes( kai ) end end
Public Instance Methods
body()
click to toggle source
# File lib/copycats/genome.rb, line 40 def body() TRAITS[:body][:kai][ @genes[:body].d ]; end
build_genes( kai )
click to toggle source
# File lib/copycats/genome.rb, line 24 def build_genes( kai ) kai = kai.reverse ## note: reserve for easy left-to-right access @genes = {} ## hash of genes (key is gene type) ## fix/todo: use as_json for "official" api order ## note: use insert order from "official" api @genes[:body] = Gene.new( kai[0,4].reverse ) @genes[:pattern] = Gene.new( kai[4,4].reverse ) @genes[:coloreyes] = Gene.new( kai[8,4].reverse ) @genes[:eyes] = Gene.new( kai[12,4].reverse ) @genes[:color1] = Gene.new( kai[16,4].reverse ) ## colorprimary / body color / base color @genes[:color2] = Gene.new( kai[20,4].reverse ) ## colorsecondary / sec color / pattern color / hi(light) color @genes[:color3] = Gene.new( kai[24,4].reverse ) ## colortertiary / acc(ent) color @genes[:wild] = Gene.new( kai[28,4].reverse ) @genes[:mouth] = Gene.new( kai[32,4].reverse ) end
build_mix_tables( other )
click to toggle source
# File lib/copycats/genome.rb, line 85 def build_mix_tables( other ) GenomeMixTables.new( self, other ).build; end
build_tables()
click to toggle source
# File lib/copycats/genome.rb, line 83 def build_tables() GenomeTables.new( self ).build; end
color1()
click to toggle source
# File lib/copycats/genome.rb, line 45 def color1() TRAITS[:color1][:kai][ @genes[:color1].d ]; end
color2()
click to toggle source
# File lib/copycats/genome.rb, line 46 def color2() TRAITS[:color2][:kai][ @genes[:color2].d ]; end
color3()
click to toggle source
# File lib/copycats/genome.rb, line 47 def color3() TRAITS[:color3][:kai][ @genes[:color3].d ]; end
coloreyes()
click to toggle source
# File lib/copycats/genome.rb, line 41 def coloreyes() TRAITS[:coloreyes][:kai][ @genes[:coloreyes].d ]; end
eyes()
click to toggle source
# File lib/copycats/genome.rb, line 42 def eyes() TRAITS[:eyes][:kai][ @genes[:eyes].d ]; end
genes_color1()
click to toggle source
# File lib/copycats/genome.rb, line 51 def genes_color1() @genes[:color1]; end
genes_eyes()
click to toggle source
# File lib/copycats/genome.rb, line 52 def genes_eyes() @genes[:eyes]; end
mix( other )
click to toggle source
add cattributes ?? why? why not?
# File lib/copycats/genome.rb, line 58 def mix( other ) mgenes = genes ## matron genes sgenes = other.genes ## sire genes new_genes = {} [:body, :pattern, :coloreyes, :eyes, :color1, :color2, :color3, :wild, :mouth].each do |key| mgene = mgenes[key] sgene = sgenes[key] new_gene = mgene.mix( sgene ) new_genes[key] = new_gene end Genome.new( new_genes ) ## return new genome from (pre-built) hash (with genes) end
mouth()
click to toggle source
# File lib/copycats/genome.rb, line 44 def mouth() TRAITS[:mouth][:kai][ @genes[:mouth].d ]; end
pattern()
click to toggle source
# File lib/copycats/genome.rb, line 43 def pattern() TRAITS[:pattern][:kai][ @genes[:pattern].d ]; end