Class: GenesReport

Inherits:
Object
  • Object
show all
Defined in:
lib/copycats/reports/genes.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



6
7
8
9
10
11
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
# File 'lib/copycats/reports/genes.rb', line 6

def build
  buf = ""
  buf << "# Genes (#{TRAITS.keys.size} x 4)\n\n"

  headings = []
  TRAITS.values.each do |trait|
    headings << "#{trait[:name]} (#{trait[:genes]})"
  end

  buf << headings.join( "" )
  buf << "\n\n"


  ## pp TRAITS
  TRAITS.values.each do |trait|

    puts "Kai	 Cattribute"
    items = []
    Kai::ALPHABET.each_char do |kai|
      value = trait[:kai][kai]
      code  = "#{trait[:code]}%02d" % Kai::NUMBER[kai]   ## e.g. FU00, FU01, FU02, etc.
      value = '?'  if value.nil? || value.empty?
      items << [kai, code, value]
    end

    items.each do |item|
      puts "#{item[0]} #{item[1]} #{item[2]}"
    end

    buf << "## #{trait[:name]} (#{trait[:code]}) - Genes #{trait[:genes]}\n\n"
    buf << make_table( items )
    buf << "\n\n"
  end

  puts buf

  buf
end

#kitties_search(q) ⇒ Object

todo/fix: use “shared” link helpers!!!!!



48
49
50
# File 'lib/copycats/reports/genes.rb', line 48

def kitties_search( q )
 "https://www.cryptokitties.co/search?include=sale,sire,other&search=#{q}"
end

#make_rows(items, columns: 2) ⇒ Object

helpers



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/copycats/reports/genes.rb', line 86

def make_rows( items, columns: 2 )
  offset = items.size / columns
  pp offset

  rows = []
  offset.times.with_index do |row|
    ## note: construct [items[row],items[offset+row],items[offset*2+row], ...]
    rows << columns.times.with_index.map { |col| items[offset*col+row] }
  end
  rows
end

#make_table(items) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/copycats/reports/genes.rb', line 53

def make_table( items )
  rows = make_rows( items, columns: 2 )    ## was 4
  pp rows

  buf = ""
  buf << "|Kai|Code|Cattribute   |Kai|Code|Cattribute  |\n"
  buf << "|--:|---:|-------------|--:|---:|------------|\n"

  rows.each do |row|
    buf << "| "

    parts = row.map do |item|
      kai  = item[0]
      name = item[2]

      if name == '?'
        cattribute = "?"
      else
        cattribute = "**[#{name}](#{kitties_search(name)})** #{MEWTATION_LEVEL[kai]}"
      end

      "#{item[0]} | #{item[1]} | #{cattribute}"
    end

    buf << parts.join( " | " )
    buf << " |\n"
  end

  buf
end

#save(path) ⇒ Object



99
100
101
102
103
# File 'lib/copycats/reports/genes.rb', line 99

def save( path )
  File.open( path, "w:utf-8" ) do |f|
    f.write build
  end
end