Class: GenomeTables

Inherits:
Object
  • Object
show all
Defined in:
lib/kittypedia/genome_tables.rb

Instance Method Summary collapse

Constructor Details

#initialize(genome) ⇒ GenomeTables

Returns a new instance of GenomeTables.



8
9
10
# File 'lib/kittypedia/genome_tables.rb', line 8

def initialize( genome )
  @genome = genome
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kittypedia/genome_tables.rb', line 12

def build
  pos = 0
  buf = ""
  buf << "Genes (256-Bit Integer Number):\n"
  buf << "- Base 10 (Decimal): #{@genome.num}\n"
  buf << "- Base 2 (Binary): #{@genome.binary}\n"
  buf << "- Base 2⁵ = 32\n"
  buf << "  - (Kai):   #{@genome.kai}\n"
  buf << "  - (Codes): #{@genome.codes}\n"
  buf << "\n\n"

  @genome.each do |slice|
    tt = slice.type

    buf << "#{tt.name} (#{tt.code}) - Genes #{tt.genes}\n\n"

###
##   fix/todo: add stars for purity?
##     ****   - all traits the same
##     ***    - two same pairs of traits
##     **     - one pair of same traits

    buf << "|Gene  |Binary   |Kai  |Code | Name     |   |\n"
    buf << "|------|---------|-----|-----|----------|---|\n"
    buf << "| #{pos} | #{slice.d.binary} | #{slice.d.kai} | #{slice.d.code} |**#{fmt_trait(slice.d)}** | d |\n"; pos+=1
    buf << "| #{pos} | #{slice.r1.binary} | #{slice.r1.kai} | #{slice.r1.code} |#{fmt_trait(slice.r1)} | r1 |\n"; pos+=1
    buf << "| #{pos} | #{slice.r2.binary} | #{slice.r2.kai} | #{slice.r2.code} |#{fmt_trait(slice.r2)} | r2 |\n"; pos+=1
    buf << "| #{pos} | #{slice.r3.binary} | #{slice.r3.kai} | #{slice.r3.code} |#{fmt_trait(slice.r3)} | r3 |\n"; pos+=1
    buf << "\n"

    if tt.key == :body    ## add legend for first entry
      buf << "d = dominant, r1 = 1st order recessive, r2 = 2nd order recessive, r3 = 3rd order recessive\n\n"
    end
  end

  buf
end

#fmt_trait(trait) ⇒ Object

helpers



53
54
55
56
57
58
# File 'lib/kittypedia/genome_tables.rb', line 53

def fmt_trait( trait )
  buf = ""
  buf << (trait.name || '')
  buf << " #{trait.tier_roman}"    if trait.tier > 0
  buf
end