Class: GenomeTables
- Inherits:
-
Object
- Object
- GenomeTables
- Defined in:
- lib/copycats/genome.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#fmt_trait(trait) ⇒ Object
helpers.
-
#initialize(genome) ⇒ GenomeTables
constructor
A new instance of GenomeTables.
Constructor Details
#initialize(genome) ⇒ GenomeTables
Returns a new instance of GenomeTables.
92 93 94 |
# File 'lib/copycats/genome.rb', line 92 def initialize( genome ) @genome = genome end |
Instance Method Details
#build ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/copycats/genome.rb', line 96 def build pos = 0 buf = "" genes = @genome.genes TRAITS.each do |key, trait| gene = genes[key] next if gene.nil? ## skip future_1, future_2, etc. buf << "#{trait[:name]} (Genes #{trait[: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 |Trait | |\n" buf << "|------|---------|-----|---------|---|\n" buf << "| #{pos} | #{Kai::BINARY[gene.d]} | #{gene.d} | **#{fmt_trait(trait[:kai][gene.d])}** | d |\n"; pos+=1 buf << "| #{pos} | #{Kai::BINARY[gene.r1]} | #{gene.r1} | #{fmt_trait(trait[:kai][gene.r1])} | r1 |\n"; pos+=1 buf << "| #{pos} | #{Kai::BINARY[gene.r2]} | #{gene.r2} | #{fmt_trait(trait[:kai][gene.r2])} | r2 |\n"; pos+=1 buf << "| #{pos} | #{Kai::BINARY[gene.r3]} | #{gene.r3} | #{fmt_trait(trait[:kai][gene.r3])} | r3 |\n"; pos+=1 buf << "\n" if 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
133 134 135 |
# File 'lib/copycats/genome.rb', line 133 def fmt_trait( trait ) (trait.nil? || trait.empty?) ? '?' : trait end |